Shawn
Shawn

Reputation: 667

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?

Upvotes: 0

Views: 777

Answers (3)

Johnny Rockex
Johnny Rockex

Reputation: 4196

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];

Upvotes: 2

Chauyan
Chauyan

Reputation: 157

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)];
    }
}

Upvotes: 0

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

Upvotes: 2

Related Questions