Iphone 识别iPad iOS 4.2的设备
我知道iOS 4.2也适用于iPad。下面的代码是我们用来识别设备的标准模式。4.2版iPad将如何改变这一点。是否应该更改代码以考虑设备类型而不是版本?Iphone 识别iPad iOS 4.2的设备,iphone,ipad,ios-4.2,Iphone,Ipad,Ios 4.2,我知道iOS 4.2也适用于iPad。下面的代码是我们用来识别设备的标准模式。4.2版iPad将如何改变这一点。是否应该更改代码以考虑设备类型而不是版本? #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 CGRect frame = [[UIScreen mainScreen] bounds]; self.view.frame = frame; #else CGRect frame = [self.view bounds];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
CGRect frame = [[UIScreen mainScreen] bounds];
self.view.frame = frame;
#else
CGRect frame = [self.view bounds];
#endif
更好的方法是[[UIDevice currentDevice]userInterfaceIdiom] 首先检查currentDevice是否响应该选择器。如果不是,那就是运行iOS 3.1.x或更早版本的iPhone/iPod
如果它确实响应该选择器,则可以检查UIUserInterfaceIdiomPhone或UIUserInterfaceIdiomPad的结果 检查设备版本和相应的代码
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version == 4.2)
{
CGRect frame = [[UIScreen mainScreen] bounds];
self.view.frame = frame;
}
else
self.view.frame = frame;
使用此代码可能会对您有所帮助。您也可以尝试以下操作:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// type you code for iPad
} else {
// type you code for iPhone
}
#endif