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

不工作:

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

不工作:

[UIApplication sharedApplication].statusBarHidden = YES;

无法登录苹果开发者论坛


当前回答

尝试添加以下方法到你的应用程序的根视图控制器:

- (BOOL)prefersStatusBarHidden
    {
        return YES;
    }

其他回答

我发现在整个应用程序中隐藏状态栏最简单的方法是在UIViewController上创建一个类别并覆盖prefersStatusBarHidden。这样你就不必在每个视图控制器中都写这个方法。

UIViewController+HideStatusBar.h

#import <UIKit/UIKit.h>

@interface UIViewController (HideStatusBar)

@end

UIViewController+HideStatusBar.m

#import "UIViewController+HideStatusBar.h"

@implementation UIViewController (HideStatusBar)

//Pragma Marks suppress compiler warning in LLVM. 
//Technically, you shouldn't override methods by using a category, 
//but I feel that in this case it won't hurt so long as you truly 
//want every view controller to hide the status bar. 
//Other opinions on this are definitely welcome

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

#pragma clang diagnostic pop


@end

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

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

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

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

View controller-based status bar appearance --- NO

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

[[UIApplication sharedApplication] setStatusBarHidden:YES];

Swift 2.0+ IOS 9

override func prefersStatusBarHidden() -> Bool {
return true
}

在你的app plist文件中添加一行“View controller based status bar appearance”,并将其设置为NO

注意,如果你在应用中使用UIImagePickerController,这是行不通的。

来自http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/, mgiroux的解决方案

隐藏特定viewController的状态栏

- (BOOL)prefersStatusBarHidden {
    return YES;
}

设置状态栏为应用程序隐藏:

在.plist中设置基于控制器的状态栏的外观 和在应用程序:didFinishLaunchingWithOptions: set: (应用程序setStatusBarHidden:是的); 注意:setStatusBarHidden:已弃用

OR

在“项目设置”中->“常规”页签->“部署信息” 检查隐藏状态栏框。