用于版本控制的 #ifdef 宏
我使用宏来区分版本,但我不能强迫它正常工作。我使用:
#ifdef _IPHONE_4_0
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
and
#if __IPHONE_OS_VERSION_MAX_ALLOWED < _IPHONE_4_0
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#endif
and
#if defined(__IPHONE_4_0)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
无论我使用什么版本 - 总是只调用其中一行。并且 __IPHONE_4_0 始终被定义。有什么想法吗?
I use macros to differ the versions but I can't force it to work properly. I used:
#ifdef _IPHONE_4_0
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
and
#if __IPHONE_OS_VERSION_MAX_ALLOWED < _IPHONE_4_0
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#endif
and
#if defined(__IPHONE_4_0)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
No matter what version I use - always called only one of the lines. And the __IPHONE_4_0 is always defined. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
#if...
处理器指令在编译时解析。只要您针对 4.0 SDK 进行编译,则始终会选择 4.0 变体。如果您想让该应用程序适用于 < 4.0,您应该使用运行时检查:
The
#if…
processor directives are resolved at compile time. As long as you compile for the 4.0 SDK, the 4.0 variant will always be chosen.If you intend to make the app works for < 4.0, you should use a runtime check:
一个小变化 -
以下代码应该可以工作:
请注意它是 __IPHONE_4_0 而不是 _IPHONE_4_0
A small change -
The following code should work:
Plz note it's __IPHONE_4_0 not _IPHONE_4_0