2010-11-30 79 views
0

我明白iOS 4.2也适用于iPad。下面的代码是我们用来识别设备的标准模式。 4.2 iPad会如何改变。我应该更改代码来考虑设备类型而不是版本?识别iPad的设备iOS 4.2

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 
    CGRect frame = [[UIScreen mainScreen] bounds]; 
    self.view.frame = frame; 
#else 
    CGRect frame = [self.view bounds]; 
#endif 

回答

5

一个更好的方式是[的UIDevice currentDevice] userInterfaceIdiom]

首先检查currentDevice响应该选择。如果不是,那么它是运行iOS 3.1.x或更低版本的iPhone/iPod。

如果它确实响应该选择器,则可以检查UIUserInterfaceIdiomPhone或UIUserInterfaceIdiomPad的结果。

0

检查设备版本和代码相应

float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (version == 4.2) 
    { 
     CGRect frame = [[UIScreen mainScreen] bounds]; 
    self.view.frame = frame; 

    } 
else 
    self.view.frame = frame; 

使用此代码,它可以帮助你。

2

你也可以试试这个:

#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