如何隐藏iOS 7.1中的状态栏?

在iOS 7.0中,我通过添加隐藏了应用程序中的状态栏

<key>UIStatusBarHidden</key> <true/> <key>UIViewControllerBasedStatusBarAppearance</key> <false/> 

到info.plist。 我只是将我的testingiPad更新到iOS 7.1,状态栏现在回到我所有的应用程序中。 我怎样才能隐藏在7.0和7.1?

更新:这只发生在iPad上运行的iPhone应用程序,我没有看到iPhone或模拟器上的这个问题。

在隐藏状态栏的视图控制器中,添加以下方法

 - (BOOL)preferStatusBarHidden { return YES; } 

那你可以打电话

 [self setNeedsStatusBarAppearanceUpdate]; 

这将改变状态栏。 这个调用可以在animation块内部完成,animation块将animation变化。

尝试添加以下内容

  - (void)viewWillAppear:(BOOL)animated{ NSLog(@"View will appear"); [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; } - (void)viewWillDisappear:(BOOL)animated{ [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; } 

我可以在模拟器中使用iPhone兼容模式下运行的单视图仅iPhone应用程序重现问题。 但只有在iOS 7.1上selectiPad非视网膜时才可以。

我的发现:

  • 无论您在plist中还是在代码中指定的状态栏都不会被隐藏。
  • 这个问题不会发生在视网膜的iPad上
  • 在iOS 7或iOS 6上不会发生此问题

我在.plist中试过这些键:

 <key>UIStatusBarHidden</key> <true/> <key>UIStatusBarHidden~ipad</key> <true/> 

 <key>UIViewControllerBasedStatusBarAppearance</key> <false/> <key>UIViewControllerBasedStatusBarAppearance~ipad</key> <false/> 

我也尝试了@Irfan提到的基于ViewController的解决scheme无济于事。

也似乎没有办法检测状态栏是否显示为[UIApplication sharedApplication] .statusBarFrame返回{0,0,0,0}

添加到ViewDidLoad:

  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; 

下面的实现方法:

 - (BOOL)prefersStatusBarHidden { return YES; } 

它会隐藏你实现它的特定ViewController的状态栏。 它对我来说非常有用。 希望它也会帮助你。

我find的唯一的解决办法是添加以下内容:

 - (UIStatusBarStyle) preferredStatusBarStyle { return -1; } 

无论你在哪里:

 - (BOOL)prefersStatusBarHidden { return YES; } 

这显然是可怕的,但似乎对我来说至less是如此 – 至less目前为止。

更新:我已经注意到这导致输出如下:

 <Error>: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. 

我发现另一个解决方法,可能是这个错误是什么使这个解决方法工作,所以我坚持下去,但值得注意的。