I have a simple test app setup like so:
UITabBarController ---> UINavigationController --->[root to]---> UIViewController
The purple bar is simply just a UIView with a button inside it. Constraints on this view are:
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:
(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:
(source: giphy.com)
Any ideas? Is this a bug overlooked by Apple devs or am I using the framework incorrectly?