我需要找出的原因是,在 iPad 上,UIPickerView 在横向和纵向上具有相同的高度。在 iPhone 上情况有所不同。 iPad 编程指南向 UIDevice 引入了一个“idiom”值:
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
// iPad
}
else
{
// iPhone
}
当你使用 iPad (3.2) 但不是 iPhone (3.1.3) 时,它可以正常工作 - 所以看起来还需要一个 ifdef 来有条件地编译该检查,例如:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
// etc.
}
#endif
对我来说,这开始看起来非常笨拙。有什么更好的办法呢?
在运行时检查(第一种方法)与编译时检查#if 完全不同。预处理器指令不会为您提供通用的应用程序。
首选方法是使用 Apple 的宏:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}
使用 3.2 作为基础 SDK(因为 3.2 之前未定义宏),您可以定位之前的操作系统版本以使其在 iPhone 上运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)