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

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

问题描述

在为 iPad 编译时是否设置了特定的 Xcode 编译器标志?

Is there a specific Xcode compiler flag that gets set when compiling for iPad?

我想有条件地编译 iPad vs 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

推荐答案

用于 iPad 与 iPhone/iPad Touch 的运行时检查的正确 API 是:

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)

所以你可以说,否定:

BOOL deviceIsPad = (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);

这篇关于在为 iPad 编译时是否设置了特定的 Xcode 编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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