简体   繁体   English

隐藏导航栏/状态栏/提示

[英]Hiding navigation bar/status bar/prompt

For the life of me, I cannot figure out how to get rid of the white bar at the top of my app. 为了我的一生,我无法弄清楚如何摆脱应用顶部的白条。 http://cl.ly/image/3Z2I1x0H3H17 http://cl.ly/image/3Z2I1x0H3H17

I am currently using a navigation controller as the root view. 我目前正在使用导航控制器作为根视图。 I've also tried just having a UIViewController as the root view. 我也尝试过仅将UIViewController作为根视图。

In the first UIViewController I have tried: 在第一个UIViewController中,我尝试过:

- (void)viewWillAppear:(BOOL)animated {
  [[self navigationController] setNavigationBarHidden:YES animated:NO];
}

This does nothing. 这什么也没做。

I have also tried: 我也尝试过:

- (BOOL)prefersStatusBarHidden {
  return YES;
}

Which hides the status icons (battery, cell connection indicator). 隐藏状态图标(电池,电池连接指示器)。

But really, I just want all that white space gone. 但实际上,我只希望所有空白都消失了。

Try: 尝试:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

Or set Status Bar to 'None' in the XIB. 或在XIB中将状态栏设置为“无”。

In viewDidLoad add this code: 在viewDidLoad中添加以下代码:

//checks if device is running iOS 7 (or newer) or iOS 6 (or older)
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
     [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
     [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

Then add this method: 然后添加此方法:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

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

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