#define 基于平台 [iPhone 或 iPad]

发布于 2024-11-09 04:48:57 字数 412 浏览 6 评论 0原文

我正在尝试使我的 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 技术交流群。

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

发布评论

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

评论(2

千鲤 2024-11-16 04:48:57

虽然可能不是最优雅的解决方案,但为了防止对代码进行重大重写,我决定使用以下技巧:

#define iPad    UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define imgAmcWidth         (iPad ? 639.0f : 240.0f)
// etc..

While probably not the most elegant solution but to prevent a major rewrite of the code I decided to use the following trick:

#define iPad    UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define imgAmcWidth         (iPad ? 639.0f : 240.0f)
// etc..
神经暖 2024-11-16 04:48:57

UI_USER_INTERFACE_IDIOMUIUserInterfaceIdiomPad 不是预处理器的东西。它们是 iOS 的一部分,因此您应该这样做:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    <define your constants here>
} else {
    <define your constants here>
}

另请参阅 如果您计划支持 3.2 之前的 iOS 版本,请使用此

UI_USER_INTERFACE_IDIOM and UIUserInterfaceIdiomPad are not preprocessor things. They are part of iOS, so you should do:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    <define your constants here>
} else {
    <define your constants here>
}

See also this if you plan to support iOS versions previous to 3.2

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