为 iPad 进行编译时是否设置了特定的 Xcode 编译器标志?
我想有条件地编译 iPad 与 iPhone/iPod Touch 代码,例如:
#ifdef TARGET_IPAD
code for iPad
#else
code for iPhone
#endif
我知道 TargetConditionals.h 中已经有 TARGET_OS_IPHONE 和 TARGET_CPU_ARM,但是有什么可以轻松且专门针对 iPad 的吗?
-Rei
用于运行时检查 iPad 与 iPhone/iPad Touch 的正确 API 是:
BOOL deviceIsPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
UIDevice 头文件管理器还包含一个方便的宏 UI_USER_INTERFACE_IDIOM(),如果您的部署目标是
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)
所以你可以消极地说:
BOOL deviceIsPad = (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)