0

我知道 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];
#endif
4

3 回答 3

5

更好的方法是 [[UIDevice currentDevice] userInterfaceIdiom]

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

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

于 2010-11-30T03:09:58.663 回答
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
于 2010-11-30T07:10:58.227 回答
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;

使用此代码可能会对您有所帮助。

于 2010-11-30T04:02:12.073 回答