我刚刚把我的iPhone 5 iOS 7升级到四个测试版。现在,当我从Xcode 5在iPhone上运行我的应用程序时,状态栏没有隐藏,尽管它应该隐藏。

不工作:

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

不工作:

[UIApplication sharedApplication].statusBarHidden = YES;

无法登录苹果开发者论坛


当前回答

这个线程上的许多答案都是有效的,但我的理解是,如果你试图做任何动态的事情,你最终需要调用:

[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];

其他回答

试试这个简单的方法:

- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}

在视图控制器中添加方法。

- (BOOL)prefersStatusBarHidden {
    return YES;
}

唯一对我有用的是在你的plist中添加以下内容

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

你可以检查这段代码,pod UIViewController+ODStatusBar

为了隐藏状态栏,我必须做以下两项更改:

添加以下代码到视图控制器,你想隐藏状态栏:

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

将此添加到您的。plist文件(在应用程序设置中转到'info')

View controller-based status bar appearance --- NO

然后你可以调用这一行来隐藏状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES];