info.plist文件中,View controller-based status bar appearance项设为YES,则View controller对status bar的设置优先级高于application的设置。为NO则以application的设置为准,view controller的prefersStatusBarHidden方法无效,是根本不会被调用的。
ios7:
1,如果View controller-based status bar appearance 设为YES。
[self setNeedsStatusBarAppearanceUpdate];
- (BOOL)prefersStatusBarHidden
{return YES;}
2,如果View controller-based status bar appearance 设为NO。 测试结果为此时可用1的方法隐藏
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
ios6:[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
取info.plist中 View controller-based status bar appearance中的设置:
NSNumber *isVCBasedStatusBarAppearanceNum = [[NSBundle mainBundle]objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
if (isVCBasedStatusBarAppearanceNum) {
_isVCBasedStatusBarAppearance = isVCBasedStatusBarAppearanceNum.boolValue;
} else {
_isVCBasedStatusBarAppearance = YES; // default
}