Brian
Brian

Reputation: 15740

How can I hide the status bar in iOS 7.1?

In iOS 7.0, I hid the status bar in my apps by adding

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

to the info.plist. I just updated my testing iPad to iOS 7.1, and the status bar is now back in all of my apps. How can I hide it in both 7.0 and 7.1?

Update: This is only happening in iPhone apps running on the iPad, I don't see this problem on the iPhone or in the simulator.

Upvotes: 15

Views: 4919

Answers (5)

Bjorn Roche
Bjorn Roche

Reputation: 11469

The only solution I have found to this is to add the following:

- (UIStatusBarStyle) preferredStatusBarStyle {
    return -1;
}

wherever you have:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

This is obviously terrible, but it seems to work for me -- at least so far.

UPDATE: I have noticed this causing output like the following:

<Error>: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

I find another workaround, and it's possible that this error is what makes this workaround work, so I'm sticking with it, but it's worth noting.

Upvotes: 0

Morris
Morris

Reputation: 613

I can reproduce the problem with a single-view iPhone-only app running in iPhone-compatibility mode in the simulator. But only when selecting an iPad non-retina on iOS 7.1.

My findings:

  • The status bar will not be hidden, whatever you specified in the plist or in code.
  • The problem doesn't occur on retina iPads
  • The problem doesn't occur on iOS 7 or iOS 6

I tried these keys in the .plist:

<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>

and

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance~ipad</key>
<false/>

I also tried the ViewController based-solution as mentioned by @Irfan to no avail.

There also seems no way to detect if the statusbar is shown as [UIApplication sharedApplication].statusBarFrame returns {0, 0, 0, 0}

Upvotes: 1

Irfan
Irfan

Reputation: 4331

Add this to ViewDidLoad:

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

And Implement below Method:

- (BOOL)prefersStatusBarHidden {
return YES;
 }

It will hide status-bar of that particular ViewController in which you Implement it. It works superbly good for me. Hopefully it will also help you out.

Upvotes: 0

4GetFullOf
4GetFullOf

Reputation: 1738

Try adding the following

   - (void)viewWillAppear:(BOOL)animated{
        NSLog(@"View will appear");
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

    }

    - (void)viewWillDisappear:(BOOL)animated{

        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    }

Upvotes: 1

thedrick
thedrick

Reputation: 211

In the view controllers in which you want the status bar hidden, add the following method

- (BOOL)preferStatusBarHidden {
  return YES;
}

Then you can call

[self setNeedsStatusBarAppearanceUpdate];

which will fire the change to the status bar. This call can be done inside of an animation block which will animate the change.

Upvotes: 1

Related Questions