#define 基于平台 [iPhone 或 iPad]
我正在尝试使我的 iPhone 应用程序与 iPad 兼容。 在头文件中我设置了一些常量。 由于屏幕较大,我希望 iPad 上用于图像的一些常量比 iPhone 上更大。 我在互联网上找到了一些建议来完成此任务:
#if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define imgAmcWidth 656.0f
#define imgAmcHeight 36.0f
#else
#define imgAmcWidth 240.0f
#define imgAmcHeight 20.0f
#endif
这似乎满足了我的需求。 不幸的是,xcode 4 无法编译此错误,并给出错误:“令牌“[”在预处理器中无效..”[LLVM GCC 4.2]。 我做错了什么?
I'm trying to make my iPhone app compatible with the iPad.
In a header file I set up some constants.
Because of the larger screen I want some constants used for images to be larger on the iPad than on to the iPhone.
I found some suggestions on the internet to accomplish this:
#if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define imgAmcWidth 656.0f
#define imgAmcHeight 36.0f
#else
#define imgAmcWidth 240.0f
#define imgAmcHeight 20.0f
#endif
This seems to satisfy my needs.
Unfortunately xcode 4 fails to compile this giving an error: 'Token "[" is not valid in preprocessor..' [LLVM GCC 4.2].
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然可能不是最优雅的解决方案,但为了防止对代码进行重大重写,我决定使用以下技巧:
While probably not the most elegant solution but to prevent a major rewrite of the code I decided to use the following trick:
UI_USER_INTERFACE_IDIOM
和UIUserInterfaceIdiomPad
不是预处理器的东西。它们是 iOS 的一部分,因此您应该这样做:另请参阅 如果您计划支持 3.2 之前的 iOS 版本,请使用此
UI_USER_INTERFACE_IDIOM
andUIUserInterfaceIdiomPad
are not preprocessor things. They are part of iOS, so you should do:See also this if you plan to support iOS versions previous to 3.2