问题描述
是否有特定的Xcode编译器标志在编译iPad时设置?
Is there a specific Xcode compiler flag that gets set when compiling for iPad?
我想有条件地编译iPad与iPhone / iPod Touch代码,例如:
I want to conditionally compile iPad vs iPhone/iPod Touch code for example:
#ifdef TARGET_IPAD
code for iPad
#else
code for iPhone
#endif
我知道TargetConditionals.h中已经有TARGET_OS_IPHONE和TARGET_CPU_ARM但是任何容易且专门针对iPad的东西?
I know there is already TARGET_OS_IPHONE and TARGET_CPU_ARM in TargetConditionals.h but anything that easily and specifically targets iPad?
-Rei
推荐答案
用于运行的正确API iPad与iPhone / iPad Touch的时间检查是:
The correct API to use for run-time checking of iPad vs. iPhone/iPad Touch is:
BOOL deviceIsPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
UIDevice头文件管理器还包括一个方便的宏UI_USER_INTERFACE_IDIOM(),如果你的部署有用目标是< iPhone 3.2。
The UIDevice header filer also includes a convenient macro, UI_USER_INTERFACE_IDIOM(), which will be helpful if your deployment target is < iPhone 3.2.
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)
所以你可以说是消极的:
So you could just say, negatively:
BOOL deviceIsPad = (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);
这篇关于在编译iPad时是否有一个特定的Xcode编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!