动态隐藏状态栏

时间:2014-09-05 21:01:35

标签: ios objective-c uinavigationcontroller statusbar

我想在点击按钮时隐藏状态栏。我试过了:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

我没有运气。我错过了什么吗?

3 个答案:

答案 0 :(得分:2)

简单的方法是,转到info.plist文件。添加行,“查看基于控制器的状态栏外观”并设置为NO。检查作为答案

答案 1 :(得分:1)

仅用于在代码中进行切换:

-(void)statusBarShouldHide:(bool)hide{

    hideStatusBar = hide;
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}
-(bool)prefersStatusBarHidden{
    return hideStatusBar;
}

呼叫者:

[self statusBarShouldHide:true];

答案 2 :(得分:0)

如果你想编程的话 试试这个。

覆盖功能

-(BOOL) prefersStatusBarHidden {
    return needHideStatusBar;
}

-(IBAction) checkStatus {

    // do your judgment here 

    needHideStatusBar = YES;
    if ([self 
        respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}