Reputation: 15740
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
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
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:
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
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
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
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