info.plist文件中,View controller-based status bar appearance項設爲YES,則View controller對status bar的設置優先級高於application的設置。爲NO則以application的設置爲準,view controller的prefersStatusBarHidden方法無效,是根本不會被調用的。app
1、若是View controller-based status bar appearance 設爲YES。orm
這時 view controller中對status bar的設置優先級高於application的設置,用下面的方式隱藏status bar:it
一、在view controller中調用setNeedsStatusBarAppearanceUpdate,更新status bar的顯示。io
- (void)viewDidAppear:(BOOL)animatedform
{sed
[super viewDidAppear:animated];object
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {date
[self prefersStatusBarHidden];select
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];方法
}
}
二、覆蓋view controller的prefersStatusBarHidden的實現,返會YES。
- (BOOL)prefersStatusBarHidden
{
return YES;
}
2、若是View controller-based status bar appearance 設爲NO,這時application的設置優先級最高,用下面的方式隱藏status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
綜合上面的結論,若是iOS6和iOS7都支持,則處理方式以下:
1、若是View controller-based status bar appearance 設爲NO。
則在iOS6和iOS7都是用下面的方法隱藏status bar。
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
2、若是View controller-based status bar appearance 設爲YES。
則須要判斷當前是iOS6仍是iOS7。若是是iOS6,則還經過sharedApplication隱藏。
若是是iOS7,則用setNeedsStatusBarAppearanceUpdate加prefersStatusBarHidden的方式來隱藏 status bar。
取info.plist中 View controller-based status bar appearance中的設置:
NSNumber *isVCBasedStatusBarAppearanceNum = [[NSBundle mainBundle]objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
if (isVCBasedStatusBarAppearanceNum) {
_isVCBasedStatusBarAppearance = isVCBasedStatusBarAppearanceNum.boolValue;
} else {
_isVCBasedStatusBarAppearance = YES; // default
}