ChatGPT解决这个技术问题 Extra ChatGPT

Status bar won't disappear

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?


Q
Quentin

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

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

How to do this globally?
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).
@PsychoDad Check my answer for a more global solution.
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!
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.
c
cmd

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.


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...
works fine, do not forget to set .plist value for "Status bar is initially hidden" to YES.
Wow, that was the only thing that worked with Kobold2d 2.1.0 and iOS 7, thanks very much!
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.
finally it works for me. Because -(BOOL)prefersstatusbarhidden method not working in modelview.
S
Sven

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).

https://i.stack.imgur.com/wXDWn.png

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


In my opinion, this answer is better because in my app, I only want to hide status bar in landscape mode, thanks!
thanks this helps me since i want to hide it for my entire app
In my opinion, this answer should be the best answer -> It is explained here developer.apple.com/library/prerelease/ios/documentation/…
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!
u
user_Dennis_Mostajo

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'

https://i.stack.imgur.com/EGZTv.png


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.
a
alones

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

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?
@WootWoot I also added - (BOOL)prefersStatusBarHidden { return YES; } to view controllers. Please try it.
doesn't seem to work for me.. should you actually call setNeedsStatusBarAppearanceUpdate?
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];
i
ikuramedia

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.


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.
This is the only method that worked for me on iOS8... somehow prefersStatusBarHidden doesn't get called on my view controller.
M
Mike Gledhill

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

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

Hope this helps !


!! This is the solution that worked for me in iOS 9.2, modifying the plist had no effect.
s
sohail.hussain.dyn

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

See the snapshot

https://i.stack.imgur.com/PKffd.png


x
xevser

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

S
Swindler

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


A
Arn Gao

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.


'setStatusBarHidden:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController prefersStatusBarHidden]
D
Dan Beaulieu

Swift Solution

just add this to your view controllers:

override func prefersStatusBarHidden() -> Bool {
    return true
}

R
RRN

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

t
testing

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.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now