首先在项目的info里面添加属性
View controller-based status bar appearance
如果 View controller-based status bar appearance 所对应的值设置为NO 时:
在iOS6和iOS7都是用下面的方法[[UIApplication sharedApplication]setStatusBarHidden:false]; //显示
如果 View controller-based status bar appearance 所对应的值设置为YES 时:[[UIApplication sharedApplication]setStatusBarHidden:true];//隐藏
则需要判断当前是iOS6还是iOS7:iOS 6:iOS 7及以上:[[UIApplication sharedApplication]setStatusBarHidden:false]; //显示
[[UIApplication sharedApplication]setStatusBarHidden:true];//隐藏
则用setNeedsStatusBarAppearanceUpdate加prefersStatusBarHidden的方式来隐藏 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;
}
本文介绍了在iOS开发中如何通过代码控制隐藏和显示系统状态栏,使用[[UIApplication sharedApplication]setStatusBarHidden:false]显示状态栏,而[[UIApplication sharedApplication]setStatusBarHidden:true]则可以隐藏状态栏。
1万+

被折叠的 条评论
为什么被折叠?



