How to display/hide the navigation bar and status bar separately on iPhoneX

Asked 2 years ago, Updated 2 years ago, 80 views

I would like to control the display/hide of NavigationBar and StatusBar in one iOS application.

iPhone6, iPhone7 and iPhone8 display as intended.
The status bar and navigation bar are not displayed on the first screen.
On the next screen, the status bar remains hidden and the navigation bar appears.

enter image description here

However, on iPhoneX, NavigationBar will also be displayed.

prefersStatusBarHidden in ViewController is set to YES.

Also, the height of NavigationBar will be similar to that of StatusBar.

enter image description here

If you know the solution, please let me know.

I look forward to your kind cooperation.

The code looks like the following.

FirstViewController.m

 - (void) viewDidLoad
{
    superviewDidLoad;

    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:vcanimated:YES];
}

- (BOOL) preferStatusBarHidden
{
    return YES;
}

SecondViewController.m

 - (void) viewDidLoad
{
    superviewDidLoad;

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

    self.view.backgroundColor=UIColor.cyanColor;
}

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

- (BOOL) preferStatusBarHidden
{
    return YES;
}

ios navigationbar iphone-x

2022-09-30 11:29

1 Answers

I also asked a question on StackOverFlow at my home (English version), but iPhoneX behavior, so it is not possible to display the navigation bar and not display the status bar.

Also, I was aware of it, but Apple's UI guidelines suggest that iPhoneX should display the status bar.


2022-09-30 11:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.