2

I have a simple test app setup like so:

UITabBarController ---> UINavigationController --->[root to]---> UIViewController

Storyboard setup

The purple bar is simply just a UIView with a button inside it. Constraints on this view are:

Constraints

Code inside ViewController to toggle the status bar via the button:

@IBAction func updateStatusBar(_ sender: Any) {
    UIView.animate(withDuration: 0.5, animations: {
        self.setNeedsStatusBarAppearanceUpdate()
    })
}

override var prefersStatusBarHidden: Bool {
   return !UIApplication.shared.isStatusBarHidden
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
    return .slide
}
  • All controllers in the storyboard have "Under bottom bar" and "under top bar" selected.
  • NavigationBar is set to isTranslucent = YES

The problem:

With this particular setup, when the status bar re-appears/slides down, the purple UIView is not adjusted accordingly (topLayoutGuide) and doesn't move downwards with the status bar, ending up like this:

Example
(source: giphy.com)

And then it tries to catch up and gets all weird and offset. I can prevent this from happening if I call force updates inside the animation block:

self.view.setNeedsLayout();
self.view.layoutIfNeeded();

But surely I shouldn't have to be forcing this.

  • isTranslucent = false DOES fix this, but I want a translucent nav bar.
  • This weird behaviour doesn't happen if I remove the TabBarController

Here is the behaviour I EXPECT/want to have:

How it should look
(source: giphy.com)

Any ideas? Is this a bug overlooked by Apple devs or am I using the framework incorrectly?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Dan
  • 216
  • 2
  • 6
  • Looks hard to predict what the effect will be of the implementation of `prefersStatusBarHidden`. – Andreas Dec 12 '16 at 16:32
  • By that I mean what if the framework wants to check if the status bar is in the right state: `prefersHidden == isHidden`? Nope, never – Andreas Dec 12 '16 at 16:34
  • @Andreas The logic in my code example was mostly for demonstration purposes so the toggle button would work with minimal code. In my production app, I have this set to TRUE (so its always hidden by default) and the same issue occurs. – Dan Dec 12 '16 at 17:09

0 Answers0