在我的iOS视频应用中,状态栏隐藏在一些视图控制器中。我已经使用以下代码做到了这一点。

[[UIApplication sharedApplication] setStatusBarHidden:YES];

它适用于iOS 5和iOS 6,但不适用于iOS 7。 我在特定的视图控制器中尝试了这个,

Eg:

-(BOOL)prefersStatusBarHidden { return YES; }

它工作得很好,但是我不能在父视图控制器中再次显示状态栏。


当前回答

UIApplication。setStatusBarX在iOS9已弃用 在info.plist中不推荐使用UIViewControllerBasedStatusBarAppearance=NO 我们应该在所有的视图控制器中使用preferredStatusBarX

但当涉及到UINavigationController时,它会变得更有趣:

If navigationBarHidden = true, the child UIViewController's preferredStatusBarX are called, since the child is displaying the content under the status bar. If navigationBarHidden = false, the UINavigationController's preferredStatusBarX are called, after all it is displaying the content under the status bar. The UINavigationController's default preferredStatusBarStyle uses the value from UINav.navigationBar.barStyle. .Default = black status bar content, .Black = white status bar content. So if you're setting barTintColor to some custom colour (which you likely are), you also need to set barStyle to .Black to get white status bar content. I'd set barStyle to black before setting barTintColor, in case barStyle overrides the barTintColor. An alternative is that you can subclass UINavigationController rather than mucking around with bar style. HOWEVER, if you subclass UINavigationController, you get no control over the status bar if navigationBarHidden = true. Somehow UIKit goes direct to the child UIViewController without asking the UINavigationController in this situation. I would have thought it should be the UINavigationController's responsibility to ask the child >shrugs<. And modally displayed UIViewController's only get a say in the status bar if modalPresentationStyle = .FullScreen. If you've got a custom presentation style modal view controller and you really want it to control the status bar, you can set modalPresentationCapturesStatusBarAppearance = true.

其他回答

为了更好地理解,添加一些带有评论的照片:

App在任何更改前

在名为“支持文件”的Project Navigator文件夹中找到,然后单击*。plist文件

之后你会得到不同的设置你的应用程序显示。你需要添加2个键UIStatusBarHidden和UIViewControllerBasedStatusBarAppearance。你可以简单地点击+按钮

按下+键后,你可以选择其中一个键开始打字。

正确的版本:

最后,在应用这些变化之后:

另外,你可以在这里找到另一种解决方案

斯威夫特5

使用以下步骤隐藏iOS状态栏:

打开Info.plist。 添加新的键视图控制器的状态栏外观和值设置为NO。 添加新键状态栏初始隐藏,值设置为YES。 编译项目。 状态栏应该隐藏在iOS手机现在。

最终设置截图:

这是在Xcode 10.2上运行的

iOS中隐藏状态栏的步骤 1. AppDelegate开放。M文件,添加应用程序。statusbar隐藏在didFinishLaunchingWithOptions方法中

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    application.statusBarHidden = YES;
    return YES;
    }

开放的信息。Plist和set

查看基于控制器的状态栏外观设置NO

试试;

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

我做了以下操作,它似乎是有效的(即使在iOS 8中):

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}