预处理器-IF不起作用 [英] Preprocessor-IF doesn't work

查看:98
本文介绍了预处理器-IF不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果设备是iPad,我正在尝试使用Preprocessor-Ifs进行检查。如果它是iPad,我想定义一些特定于Devices的东西,但出于某种原因,如果PP-Constant为真,我无法检入PP-IF。

I'm trying to check with Preprocessor-Ifs if the Device is an iPad. If it is an iPad, I want to define something Devicespecific, but for some reason I can't check in an PP-IF if a PP-Constant is true.

也许你有个主意?

#ifdef UI_USER_INTERFACE_IDIOM

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#else

    #define IS_IPAD false

#endif



#if IS_IPAD

    #define WIDTH 768
    #define HEIGHT 1024

#else

    #define WIDTH 320
    #define HEIGHT 480

#endif


推荐答案

在构建应用程序之前处理预处理器规则(惊讶,惊讶)。由于它是一个通用的应用程序,它还不知道它是在iPad还是iPhone上运行。

Preprocessor rules are, (surprise, surprise) processed prior to building the app. Since it's an universal app, it doesn't yet know if it's running on an iPad or an iPhone.

使用此:

#ifdef UI_USER_INTERFACE_IDIOM
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define IS_IPAD false
#endif

#define WIDTH (IS_IPAD ? 768 : 320)
#define HEIGHT (IS_IPAD ? 1024 : 480)

这篇关于预处理器-IF不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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