简体   繁体   中英

Hiding status bar on iPad scaled mode pushes window down

When I call

[[UIApplication sharedApplication] setStatusBarHidden:hideStatusBar];

on a iPad running an iPhone app on scaled mode, the status bar doesn't even hide. Instead, a 20 pixel black space gets pushed onto the top of my iPad views; ultimately getting my app rejected by apple even though I don't want anyone using this 'iPhone only' app on an iPad.

If I remove the setStatusBarHidden call, the iPhone obviously doesn't hide the status bar. On the iPad running scaled mode, the black bar doesn't show up anymore.

View controller-based status bar appearance is set to NO.

I have also tried the following:

- (BOOL)prefersStatusBarHidden
{
  return hideStatusBar;
}

and this set before I need to hide the status bar.

hideStatusBar = YES; //changes
[self setNeedsStatusBarAppearanceUpdate];

However, "prefersStatusBarHidden" isn't called. I just need a solution so that the black bar doesn't appear on the iPad scaled mode and the status bar disappears on the actual iPhone.

I'm running this on iOS 8 and 9.

I found that, in addition to the code you've got, you have to create the Info Plist BOOL item View Controller Status Bar Appearance (also called UIViewControllerBasedStatusBarAppearance ) and set it to YES.

The code that works for me is:

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:NO];

    [self setNeedsStatusBarAppearanceUpdate];
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM