隐藏状态栏
在info.plist里,View controller-based status bar appearance 项设为YES,则View controller对status bar的设置优先级高于application的设置。为NO则以application的设置为准,view controller的prefersStatusBarHidden方法无效,是根本不会被调用的。
View controller-based status bar appearance设置为YES
在ViewController里设置
- (BOOL)prefersStatusBarHidden
{
return YES;
}
而会忽略UIApplication里的设置,就算设置了隐藏为NO
[[UIApplication sharedApplication] setStatusBarHidden:NO];
View controller-based status bar appearance设置为NO
View controller-based status bar appearance设置为NO后,情况会相反,会以UIApplication里设置的为准
总结:
当需要在单个页面里隐藏状态栏时,可以有两种办法
View controller-based status bar appearance设置为YES,并在ViewController里设置prefersStatusBarHidden方法返回值为YES;
View controller-based status bar appearance设置为NO,在ViewWillAppear和ViewWillDisappear里设置
[UIApplication sharedApplication] setStatusBarHidden: 的状态