开发者

#ifdef macros for versions controlling

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 o开发者_Go百科nly one of the lines. And the __IPHONE_4_0 is always defined. Any ideas?


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:

UIApplication* app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(setStatusBarHidden:withAnimation:)])
  [app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
else
  [app setStatusBarHidden:YES animated:YES];


A small change -

The following code should work:

 #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_4_0   
       [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
 #else   
       [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
 #endif

Plz note it's __IPHONE_4_0 not _IPHONE_4_0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜