简体   繁体   中英

Dynamically hiding status bar

I want to hide the status bar at the click of a button. I have tried:

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

I have had no luck with this. Am I missing something?

The simple way is, go to the info.plist file. add row, "View controller-based status bar appearance" and set to NO. Check as an answer

For toggling on and off in code only:

-(void)statusBarShouldHide:(bool)hide{

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

called by:

[self statusBarShouldHide:true];

if you wanna do this programmingly try this.

override the funtion

-(BOOL) prefersStatusBarHidden {
    return needHideStatusBar;
}

-(IBAction) checkStatus {

    // do your judgment here 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM