1、在info.plist里面添加如下属性并设置成NO
2、在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法下添加如下两行代码
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
PS:上面的隐藏/显示状态栏的方法在
iOS9
之后被弃用了,'setStatusBarHidden:withAnimation:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController prefersStatusBarHidden]
为了
fix warning
重新找到了一个解决办法:
1、在info.plist里面添加如下属性并设置成YES
2、在BaseViewController里面做如下处理:
添加如下成员变量:
/// 隐藏statusBar
@property (nonatomic, assign) BOOL statusBarHidden;
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden {
return _statusBarHidden;
}
- (void)setStatusBarHidden:(BOOL)statusBarHidden {
if (_statusBarHidden != statusBarHidden) {
_statusBarHidden = statusBarHidden;
}
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationNone;
}
在第2点可以不在
BaseViewController
添加成员变量statusBarHidden
,然后在需要添加的ViewController里面添加以下方法即可:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden {
return NO;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationNone;
}