1

I'd like to separately control Show and Hide NavigationBar and StatusBar or each screens in my application.

On iPhone6, iPhone7 and iPhone8, it's OK.

enter image description here

But on iPhoneX, when NavigationBar is shown, StatusBar is shown together even if prefersStatusBarHidden is set as YES.

And the height of NavigationBar is taller by that of StatusBar

enter image description here

I'd appreciate if you would tell me a good resolution.

Thank you.

My code is like below,

FirstViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = UIColor.yellowColor;

    self.navigationController.navigationBarHidden = YES;
}                                 }

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

    self.navigationController.navigationBarHidden = YES;
}

- (void)touchUpButton:(UIButton *)button
                                  {
    SecondViewController *vc = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

SecondViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"SecondView";

    self.view.backgroundColor = UIColor.cyanColor;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

1 Answer 1

2

This is the expected behaviour on an iPhone X and you can't stop it. On other iPhones when you display a navigation bar and there is no status bar the navigation bar the navigation bar moves up to the top of the screen. However on the iPhone X it can't do this because the 'notch' would cut into it and you would lose part of the title. So when displaying a navigation bar the status bar is always shown.

That is one of the reasons why in the HIG for iPhone X it says this:

If your app currently hides the status bar, reconsider that decision for iPhone X. The display height on iPhone provides more vertical space for content than the displays of 4.7" iPhones, and the status bar occupies an area of the screen your app probably won't fully utilize. The status bar also displays information people find useful. It should only be hidden in exchange for added value.

As a bonus bit of information if you are making the top and bottom of the display black on an iPhone X (particularly to hide it's round corners and 'notch') then that is a quick way to get your app rejected by Apple. Again in the HIG for iPhone X it says:

Don't mask or call special attention to key display features. Don't attempt to hide the device's rounded corners, sensor housing, or indicator for accessing the Home screen by placing black bars at the top and bottom of the screen. Don't use visual adornments like brackets, bezels, shapes, or instructional text to call special attention to these areas, either.

While most of these are just guidelines Apple are very keen about this one and will almost always reject an app because of it.

7
  • Thank you for your response. I had known Apple's HIG said iOS application should show status bar because, on iPhoneX, the status information don't narrow other area thanks to the 'notch area'. How about the navigation bar height of my application ? The hight is taller than that of iPhone8. Is there any way to make it the same height as that of iPhone8 ? Thank you.
    – M.Masa
    Jan 12, 2018 at 0:52
  • It's difficult to say about the navigation bar height issue without seeing more of how you have setup the navigation bar. What constraints are you using if any, etc Jan 12, 2018 at 8:03
  • My example project has no special setting, In FirstViewController self.navigationController.navigationBarHidden = YES;, and in SecondViewController``self.navigationController.navigationBarHidden = NO; Other than that, Hide status bar is checked at Deployment Info in General setting of the project.
    – M.Masa
    Jan 12, 2018 at 9:37
  • Well looking at your image your nav bar appears to be lower on the iPhone X than normal with a black area above it. How have you done that? Jan 12, 2018 at 9:39
  • Sorry, I forgot to provide a information that my example project don't have LaunchImage of iPhoneX screen size. I'd like to resolve this issue in the condition. Thank you.
    – M.Masa
    Jan 12, 2018 at 9:46

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.