在编译iPad时是否有一个特定的Xcode编译器标志? [英] Is there a specific Xcode compiler flag that gets set when compiling for iPad?

查看:103
本文介绍了在编译iPad时是否有一个特定的Xcode编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有特定的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编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆