Status bar won't disappear
Asked Answered
E

14

113

I'm creating an application and I want the status bar hidden. When I test the app, the status bar is hidden whilst the splash screen is shown, but once the app is fully loaded, the status bar reappears.

I'm using Xcode 5 and iOS 7, and have tried disabling the status bar programatically

  ([[UIApplication sharedApplication] setStatusBarHidden:YES    
      withAnimation:UIStatusBarAnimationFade];),

in the info.plist file, and using the attributes inspector on the .xib file. Nothing appears to work.

Any ideas?

Exudation answered 20/7, 2013 at 15:22 Comment(0)
B
220

Try adding the following method to your app's root view controller:

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
Burlingame answered 30/7, 2013 at 18:11 Comment(8)
How to do this globally?Blip
Also, as stated in the Apple docs, you should call the [self setNeedsStatusBarAppearanceUpdate]; after calling this method with something other than the default value (the default value is NO).Dither
@PsychoDad Check my answer for a more global solution.Territus
Perfect, thank you. I just can't figure out why iOS 7 is doing this and not respecting XIBs that contain NO status bar settings!Adamic
Adding this on a ViewController added to the stack is all I needed to hide the statusbar in that viewcontroller; the statusbar returns when this viewcontroller is removed.Stoll
WHERE do you call setNeedsStatusBarAppearanceUpdate ?!! Inside prefersStatusBarHidden?? (It seems to work even if you don't call setNeedsStatusBarAppearanceUpdate.)Loralyn
@joeBlow I think what manderson is saying is that if you change the return value of the prefersStatusBarHidden method (like if you have more complicated logic than just 'return YES;') you'll need to call setNeedsStatusBarAppearanceUpdate to force iOS to call your prefersStatusBarHidden again.Burlingame
BTW for anyone reading, this is the only solid solution I've found iOS7, https://mcmap.net/q/67339/-ios-7-status-bar-overlaps-camera-controls-on-uiimagepickercontroller !!Loralyn
T
125

You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".

This will enable you to set the status bar to hidden mode. This sets it to a global unlike other provided answers.

UPDATE: If you want that the status bar would be hidden on splash screen don't forget to mark "Hide during application launch" on target status bar options. Also, you can add "Status bar is initially hidden" to "YES" on the plist if you don't want to do it with code inside the app.

Territus answered 19/9, 2013 at 23:56 Comment(13)
Took me a lot of time to figure this out. It is a problem I think everyone would have and Apple didn't mention it enough. glad to help...Territus
works fine, do not forget to set .plist value for "Status bar is initially hidden" to YES.Illuminism
Wow, that was the only thing that worked with Kobold2d 2.1.0 and iOS 7, thanks very much!Ahrendt
What if you do want this plist value to be YES but hide the status bar for just 1 or 2 UIViewControllers?Deutero
Apple are not really champions of backward compatibility. Let's all dance to their flute and update every single one of our apps. Sorry, venting frustration. Caused by Apple.Uniformed
I noticed that the solution worked for all simulators except iPhone Retina 4-inch 64-bit iOS 7.0, where the status bar appeared overlayed on the splash screen. I had to additionally set "Status bar is initially hidden" to YES.Gleich
@Gleich This is true also to regular iPhone. but it's not so relevant to the case. I'll add that any case. thanksTerritus
finally it works for me. Because -(BOOL)prefersstatusbarhidden method not working in modelview.Verrazano
You should really avoid using this deprecated approach to appearance management. Instead, learn how view controllers can control the appearance of the status bar.Calcareous
@Ihunath How (without building all the app from scratch)?Territus
This is the correct answer... because I want to appear and disappear the bar from time to time and "prefersStatusBarHidden" method is permanentBorak
@Borak True, but you could also return "NO" in some cases (should be really careful there).Territus
It worked for me, thanks Idan // to show in specific view controller UIApplication.shared.isStatusBarHidden = false // to hide in specific view controller UIApplication.shared.isStatusBarHidden = trueWifehood
S
73

The code you posted works for iOS 6.1 and below. For iOS 7, Apple has made new methods available to directly control the status bar for each view. Turning off this option in your Info.plist will enable you to hide the status bar, at least for the current Developer Preview (4).

Add this and set to NO

For reference, please take a look at the iOS 7 transition guide that's available on Apple's developer portal.

Suzannesuzerain answered 30/7, 2013 at 11:58 Comment(4)
In my opinion, this answer is better because in my app, I only want to hide status bar in landscape mode, thanks!Poltergeist
thanks this helps me since i want to hide it for my entire appMideast
In my opinion, this answer should be the best answer -> It is explained here developer.apple.com/library/prerelease/ios/documentation/…Scissile
I've done this, but it looks like it has just hidden the status bar, however, my app is still 'pushed down' by the amount of space the status bar would take up, and I can still see the battery indicator!Ribosome
C
35

well I try hide the status bar in all my app and in the "app"-info.plist and I add two rows in the dictionary "Information Property List" I add "View controller-based status bar appearance" set NO and in "Status bar is initially hidden"set YES and for me works n_n'

plist info

Corin answered 19/9, 2013 at 23:2 Comment(1)
This forces your app into a compatibility mode designed solely to make old apps run as intended on iOS 7 when developers have no time to fix the app for the new way to do things. Instead, you need to implement the prefer* methods in your view controllers.Calcareous
K
17

However, if you use UIImagePicker, the status bar appears again.

In that case, you should hide the status bar as below,

- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {

// for iOS7
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }
Kirwan answered 11/9, 2013 at 17:34 Comment(4)
I'm having the same issue. The status bar is hidden until I use UIImagePicker. I tried your solution and it isn't working for me. Did I need to add anything besides the code in your post?Haemo
@WootWoot I also added - (BOOL)prefersStatusBarHidden { return YES; } to view controllers. Please try it.Kirwan
doesn't seem to work for me.. should you actually call setNeedsStatusBarAppearanceUpdate?Orate
I need to hide status bar on a button click. I have tried below code but it didn't worked. Can some one please help me. [[UIApplication sharedApplication] setStatusBarHidden:YES];Esquimau
L
7

After some long searching, I finally found a very simple solution which also takes care of the UIImagePickerController problem.

As mentioned in the other answers, set your status bar hidden in your AppDelegate didFinishLaunching, and set the "View controller-based status bar appearance" to NO.

Then, in your AppDelegate:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
      [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

et voila - your Status Bar will remain hidden even when the UIImagePickerController is foremost.

This is better than 'rehiding' it every time you present a UIImagePickerController as it remains hidden throughout the app.

Lustreware answered 20/9, 2013 at 8:7 Comment(2)
Although something still seems broken in iOS7 on iPad at least - the UIImagePickerController still throws up a status bar the second time it's shown... Hurrrr... :-( Currently I'm using the appDelegate along with hiding it again in every viewWillAppear. So even if it looks dirty for a short while it gets fixed again quickly.Lustreware
This is the only method that worked for me on iOS8... somehow prefersStatusBarHidden doesn't get called on my view controller.Sponsor
L
7

To hide the status bar on a particular UIViewController, simply add this:

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

Hope this helps !

Limnetic answered 7/4, 2014 at 10:29 Comment(1)
!! This is the solution that worked for me in iOS 9.2, modifying the plist had no effect.Sestet
R
5

You can hide from the project summary. there is a checkbox hide during launch.

See the snapshot

enter image description here

Rapids answered 10/9, 2013 at 6:19 Comment(0)
V
4

I found this solution for me. It works like a charm. Write this code on your viewcontroller which you wanted to use UIImagePickerController on.

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
     }
Vina answered 26/12, 2013 at 22:6 Comment(0)
G
3

In addition to the answer from alones above, make sure to implement the imagePickerControllerDidCancel method and add the same code there too.

Gratification answered 12/9, 2013 at 5:52 Comment(0)
H
2

I was having issues with UIImagePicker as well. Similar to Alones answer, my solution was the following. I added this line or code:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

to this function:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

I haven't tested this with iOS 6 or older but it works great in iOS 7.

Haemo answered 19/9, 2013 at 21:59 Comment(1)
'setStatusBarHidden:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController prefersStatusBarHidden]Doubler
L
2

Swift Solution

just add this to your view controllers:

override func prefersStatusBarHidden() -> Bool {
    return true
}
Lorraine answered 9/8, 2015 at 20:20 Comment(0)
A
0

I am using Xcode 6, this solution works on iOS 7 and 8 for me:

First, Set the "View controller-based status bar appearance" to NO in plist file.

Second, in AppDelegate, add this:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
      [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
Apocarp answered 11/10, 2014 at 11:48 Comment(0)
S
0

My problem was that I used view controller containment. Only the top most view controller, which is embedded into a navigation controller for example, can hide or show the status bar.

Slushy answered 23/12, 2014 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.