iPhone - 如何在通用应用程序中使用#define
我正在创建在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照 Apple 的建议,用于
编写特定于平台的代码。使用三元
?:
运算符,您还可以将其合并到#define
中:如果您想使用条件编译来确定两个
#define< 中的哪一个/code> 语句应该包含在您的代码中,但不能:通用应用程序不包含适用于 iPhone 和 iPad 的两个单独的二进制文件。它只是一个二进制文件,因此所有与平台相关的决策都必须在运行时做出。
As recommended by Apple, use
to write platform-specific code. With the ternary
?:
operator, you could also incorporate this into a#define
: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.我使用此函数来检测 iPad,然后为我的应用程序的所有不同部分编写条件。
您还可以为 iPhone/iPad 加载不同的 xib 文件。
i used this function to detect iPad, and then write conditions for all different parts of my application.
Also you can load different xib files for iPhone/iPad.