DrKey
DrKey

Reputation: 3495

Hide status bar in iOS7

I need to hide the status-bar on iOS7. I already tried to set:

Status bar is initially hidden

and

View controller-based status bar appearance

into the plist file. Status-bar doesn't appears when app in launched, but when I change view-controller (is a tabbed app) status-bar appears!

I already tried to set

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

and

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

in a view-controller, but doesn't works. Any ideas?

Thank you in advance :)

UPDATE

I partially resolve the issue by setting "View controller-based status bar appearance" to "YES" into info.plist and calling the method

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

into the view-controller. But now I got another problem: status-bar appears when I launch another controller (UIImagePickerController). I tried to set [myPicker prefersStatusBarHidden]; but it seems to be read-only. Anyone know the solution?

P.S.: UIViewControllerBasedStatusBarAppearance = NO and UIViewControllerBasedStatusBarAppearance = NO are the same thing..

Upvotes: 3

Views: 3343

Answers (2)

Gabriele Petronella
Gabriele Petronella

Reputation: 108091

Set

UIViewControllerBasedStatusBarAppearance = YES

in the info.plist and in each controller implement

- (BOOL)prefersStatusBarHidden {
    return YES; // or NO
}

Then whenever you need a status bar appearance update (e.g. in the viewDidLoad of a controller) call setNeedsStatusBarAppearanceUpdate.

As per the documentation of setNeedsStatusBarAppearanceUpdate:

Call this method if the view controller's status bar attributes, such as hidden/unhidden status or style, change. If you call this method within an animation block, the changes are animated along with the rest of the animation block.

So for instance

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNeedsStatusBarAppearanceUpdate];

    ...
}

will hide/unhide the status bar (aside from other potential style changes) whenever the view controller's view loads.

Optionally you can also animate the transition wrapping the call in an animation block

- (void)viewDidLoad {
    [super viewDidLoad];

    [UIView animateWithDuration:0.5 animations:^{
        [self setNeedsStatusBarAppearanceUpdate];
    }]; 

    ...
}

Upvotes: 3

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

add this key to your info.plist

UIViewControllerBasedStatusBarAppearance = NO

Upvotes: 7

Related Questions