gpt4 book ai didi

iphone - 以编程方式检测 iPad/iPhone 硬件的最佳方法

转载 作者:行者123 更新时间:2023-12-03 18:11:32 26 4
gpt4 key购买 nike

我需要找出的原因是,在 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 上运行。

关于iphone - 以编程方式检测 iPad/iPhone 硬件的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2862140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com