繁体   English   中英

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

[英]How can I hide the status bar in iOS 7.1?

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

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

到info.plist。 我刚刚将测试iPad更新到iOS 7.1,状态栏现在又回到了我的所有应用程序中。 如何在7.0和7.1中隐藏它?

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

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

- (BOOL)preferStatusBarHidden {
  return YES;
}

然后你可以打电话

[self setNeedsStatusBarAppearanceUpdate];

这会将更改激活到状态栏。 此调用可以在动画块内完成,动画块将为更改设置动画。

尝试添加以下内容

   - (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上选择iPad非视网膜时。

我的发现:

  • 无论您在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的解决方案无济于事。

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

将其添加到ViewDidLoad:

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

并实施以下方法:

- (BOOL)prefersStatusBarHidden {
return YES;
 }

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

我发现的唯一解决方案是添加以下内容:

- (UIStatusBarStyle) preferredStatusBarStyle {
    return -1;
}

无论你在哪里:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

这显然是可怕的,但它似乎对我有用 - 至少到目前为止。

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

<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.

我找到了另一种解决方法,这个错误可能会使这个解决方法起作用,所以我坚持使用它,但值得注意。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM