iOS开发UI篇— View controller-based status bar appearance
一、如果View controller-based status bar appearance 设为YES。
这时 view controller中对status bar的设置优先级高于application的设置,用下面的方式隐藏status bar:
1、在view controller中调用setNeedsStatusBarAppearanceUpdate,更新status bar的显示。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
}
2、覆盖view controller的prefersStatusBarHidden的实现,返会YES。
- (BOOL)prefersStatusBarHidden
{
return YES;
}
二、如果View controller-based status bar appearance 设为NO,这时application的设置优先级最高,用下面的方式隐藏status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
综合上面的结论,如果iOS6和iOS7都支持,则处理方式如下:
一、如果View controller-based status bar appearance 设为NO。
则在iOS6和iOS7都是用下面的方法隐藏status bar。
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
二、如果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
}
posted on 2015-05-05 12:25 iosblog's 阅读(1027) 评论(0) 编辑 收藏 举报