4
votes

In some devices as iPhone 7 and 8 the navigation bar overlaps status bar after do navigating, the parent view controller has status bar hidden but I show and hide it in viewWillAppear and viewWillDisappear respectively. I tested in iOS 12 and it works.

I am using prefersStatusBarHidden to hidden the status bar.

Here the Image Navbar Overlaps Status bar

Update: Here an example project: https://github.com/FranklinSamboni/NavBarTestSwfit. It work fine in iOS 12 but with iOS 13 the navigation bar overlaps status bar in iPhone 7,8

Images with iPhone 8 (simulator) Home The second view Second View

2
I have noticed some bad layout issues on ios 13 when changing orientations etc. If you background the app and bring it back to the foreground. Does the additional layout pass fix the issue? Amerino
"If you background the app and bring it back to the foreground" doesn't work.Franklin Samboni Castillo
I edited my questions and I added a example project.Franklin Samboni Castillo
Okay you're right, sorry, there's a bug in iOS 13 where hiding the status bar makes the navigation bar shorter. I don't think there's anything we can do about it.matt

2 Answers

1
votes

Okay, I'm going to give one of those wishy-washy answers.

  • On the one hand, you've definitely found a new behavior in iOS 13. When you hide the status bar, the navigation bar shrinks. You could term this a bug in iOS 13...

  • On the other hand, it could be argued that what you are doing is wrong. If you have a navigation bar, you already cannot hide the status bar on a device without a bezel (iPhone X etc.), and now Apple seems to be assuming that if you have a navigation bar you won't hide the status bar at all. And that is a reasonable assumption, because it makes no sense to hide the status bar in portrait when there is a navigation bar, and especially in some children of the navigation controller but not others.

So you could file a bug report on this, but I don't think you'll get any joy from it. Apple is likely to reply that this is intended, or is at least a consequence of doing something they don't want to support. You have a navigation bar; allow the status bar to show.

1
votes

I faced the same problem, after a few hours research, I found a not perfect but worked solution. Hope it will work for you.The code was written with Objective-C.

In viewDidAppear method of the secondViewController, hide statusBar first and show it at once.

  1. Declare a member variable BOOL statusBarHidden in secondViewController
  2. Implement prefersStatusBarHidden method from UIViewController
     - (BOOL)prefersStatusBarHidden
     {
         return statusBarHidden;
     }
    
  3. Create a new method setStatusBarHidden
     - (void)setStatusBarHidden:(BOOL)hidden
     {
         if (statusBarHidden != hidden)
         {
             statusBarHidden = hidden;
             [self setNeedsStatusBarAppearanceUpdate];
         }
     }
    
  4. Call setStatusBarHidden in viewDidAppear
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        [self setStatusBarHidden:YES];
        [self setStatusBarHidden:NO];
    }