Status bar的显示和隐藏
- 如果想要的效果是启动时隐藏,进入软件之后显示
- 可以在设置中勾选
Hide status bar
选项
-
View controller-based status bar appearance
- NO - 代表status bar 的控制权限给了UIApplication
- YES(默认值) - 代表控制器的优先级比UIApplication高,而且这个时候使用UIApplication控制status bar 将没有效果
最简单的方法(我自己认为)
- 在info.plist中配置
View controller-based status bar appearance
为NO
- 全部页面都隐藏
- 在
AppDelegate
的application:didFinishLaunchingWithOptions:
方法中设置
[UIApplication sharedApplication].statusBarHidden = YES;
- 有的页面需要隐藏
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
控制器自己控制状态栏
- 当info.plist中没有对
View controller-based status bar appearance
设置,默认值是YES
/**
让当前控制器对应的状态栏改变颜色,是白色还是黑色
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
/**
让当前控制器对应的状态栏显示或者隐藏
*/
- (BOOL)prefersStatusBarHidden
{
return YES;
}