在我的iOS视频应用中,状态栏隐藏在一些视图控制器中。我已经使用以下代码做到了这一点。
[[UIApplication sharedApplication] setStatusBarHidden:YES];
它适用于iOS 5和iOS 6,但不适用于iOS 7。 我在特定的视图控制器中尝试了这个,
Eg:
-(BOOL)prefersStatusBarHidden { return YES; }
它工作得很好,但是我不能在父视图控制器中再次显示状态栏。
在我的iOS视频应用中,状态栏隐藏在一些视图控制器中。我已经使用以下代码做到了这一点。
[[UIApplication sharedApplication] setStatusBarHidden:YES];
它适用于iOS 5和iOS 6,但不适用于iOS 7。 我在特定的视图控制器中尝试了这个,
Eg:
-(BOOL)prefersStatusBarHidden { return YES; }
它工作得很好,但是我不能在父视图控制器中再次显示状态栏。
当前回答
在Plist中添加以下属性。
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
现在状态栏将被隐藏。
其他回答
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.
在iOS10中,我所需要做的就是覆盖我的RootViewController (Swift)中的prefersStatusBarHidden变量:
override var prefersStatusBarHidden: Bool {
return true
}
试试这个简单的方法:
objective - c:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated]
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
迅速:
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}
override func viewWillDisappear(animated: Bool)
{
super.viewWillDisappear(animated)
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}
iOS 9起:
由于statusBarHidden方法已从iOS9中弃用,您需要在plist中添加如下两个值:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
请参考以下图片:
statusBarHidden从iOS9被弃用:
@property(重述,非atomic,getter= isstatus barhiden) BOOL 新闻记者:新闻记者 prefersStatusBarHidden”)__TVOS_PROHIBITED;
要在iOS7中隐藏状态栏,你需要2行代码
在应用程序中:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions写入 [[UIApplication sharedApplication] setStatusBarHidden:YES]; 在信息。加上这个 基于视图-控制器的状态栏外观= NO