在编写移动端GIS程序的时候。常常要依据ios设备的大小来设置UI。曾经我在ios程序中,须要定义设备的值(如:宽度和高度),如:
//屏幕宽度 高度
#define kScreenWidth 320
#define kScreenHeight 548
可是假设是不同的设备。如iphone4、iphone5,甚至是ipad等设备,那么就要改变代码,非常不方便。事实上ios是提供方法来解决问题的。
例如以下所看到的:
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
另外,ipad设备或者iphone设备也是非常easy辨别的,例如以下所看到的:
//推断iphone ipad
#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define isiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)