iOS7 隐藏状态栏StatusBar

 

一 初始化

//方法一(代码设置):

现在ios7已经更改为透明,并且不占用屏幕高度。其中隐藏及显示的方法如下:

在uiviewcontroller的子类下,调用:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
– (BOOL)prefersStatusBarHidden
{
return YES;//隐藏为YES,显示为NO
}

在视图切换,比如addsubview,present,pushin等,也需要注意及修改该状态栏。

 

//方法二(在plist里设置):

首先设置key:Status bar is initially hidden    为YES

然后设置key:View controller-based status bar appearance  为NO

即可实现全局隐藏状态栏了

 

二 打开相册后,状态栏出现的问题

方法一:加category

@implementation UIImagePickerController (RemoveStatusBar)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // not an issue before IOS7 (likely to be fixed after too...
 
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}
 
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
 
- (UIViewController *)childViewControllerForStatusBarHidden
{
    return nil;
}
 
 
@end
方法二:关闭相册后,调用[[UIApplication sharedApplication] setStatusBarHidden: YES]
 

发表评论

*

* 绝不会泄露


Design By Inzaghi | 京ICP备16047555号-1