iPhone - 如何在通用应用程序中使用#define

发布于 2024-10-09 07:46:23 字数 470 浏览 0 评论 0原文

我正在创建在 iPhone 和 iPad 上运行的通用应用程序。 我正在使用 #define 创建 CGRect。我想使用两种不同的 #define - 一种用于 iPhone,一种用于 iPad。 我怎样才能声明它们,以便通用应用程序选择正确的一个......

我想我必须更新更多描述以避免混淆。 我有一个 WPConstants.h 文件,其中我声明了所有 #define,如下所示

#define PUZZLE_TOPVIEW_RECT CGRectMake(0, 0, 480, 100)
#define PUZZLE_MIDDLEVIEW_RECT CGRectMake(0, 100, 480, 100)
#define PUZZLE_BOTTOMVIEW_RECT CGRectMake(0, 200, 480, 100)

上面的内容适用于 iphone。同样,对于 iPad,我想要不同的#define 我怎样才能进一步进行?

I'm creating universal app that runs oniphone and ipad.
I'm using #define to create CGRect. And I want to use two different #define - one for iPhone and one for iPad.
How can I declare them so that correct one will be picked by universal app..........

I think I've to update little more description to avoid confusion.
I've a WPConstants.h file where I'm declaring all the #define as below

#define PUZZLE_TOPVIEW_RECT CGRectMake(0, 0, 480, 100)
#define PUZZLE_MIDDLEVIEW_RECT CGRectMake(0, 100, 480, 100)
#define PUZZLE_BOTTOMVIEW_RECT CGRectMake(0, 200, 480, 100)

The above ones are for iphone. Similarly for iPad I want to have different #define
How can I proceed further?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风启觞 2024-10-16 07:46:23

按照 Apple 的建议,用于

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { ... }
else { ... }

编写特定于平台的代码。使用三元 ?: 运算符,您还可以将其合并到 #define 中:

#define MyRect (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? CGRectMake(0,0,1024,768) : CGRectMake(0,0,480,320))

如果您想使用条件编译来确定两个 #define< 中的哪一个/code> 语句应该包含在您的代码中,但不能:通用应用程序不包含适用于 iPhone 和 iPad 的两个单独的二进制文件。它只是一个二进制文件,因此所有与平台相关的决策都必须在运行时做出。

As recommended by Apple, use

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { ... }
else { ... }

to write platform-specific code. With the ternary ?: operator, you could also incorporate this into a #define:

#define MyRect (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? CGRectMake(0,0,1024,768) : CGRectMake(0,0,480,320))

In case you wanted to use conditional compilation to determine which of two #define statements should be included in your code, you can't: a universal app does not contain two separate binaries for iPhone and iPad. It's just one binary so all platform-related decisions have to be made at runtime.

何其悲哀 2024-10-16 07:46:23

我使用此函数来检测 iPad,然后为我的应用程序的所有不同部分编写条件。

#ifdef UI_USER_INTERFACE_IDIOM
    #define isPad() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define isPad() NO
#endif

您还可以为 iPhone/iPad 加载不同的 xib 文件。

i used this function to detect iPad, and then write conditions for all different parts of my application.

#ifdef UI_USER_INTERFACE_IDIOM
    #define isPad() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define isPad() NO
#endif

Also you can load different xib files for iPhone/iPad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文