11

I've been trying to keep UINavigationBar from moving/resizing when calling setNeedsStatusBarAppearanceUpdate.

I want to keep the navigation bar at full 64px height when the status bar hides with animation.

Any help would be appreciated!

UPDATE: I was able to overcome this issue by creating a new UIWindow and covering up the status bar.

Cezary Wojcik
  • 21,745
  • 6
  • 36
  • 36
  • don't think there's any API for that. You will probably have to resize your window, maybe set `wantsFullScreenLayout` to `NO`, etc. – nielsbot Oct 27 '13 at 17:41
  • `wantsFullScreenLayout` is [deprecated](https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html) in iOS 7. – Cezary Wojcik Oct 27 '13 at 20:44
  • I think your title indicates a misunderstanding on your part. The navigation does keep the same height (44 points) when you hide the status bar, it's just that the status bar (20 points) and the navigation bar appear to be one view, when they are in fact two different views. Are you trying to do this with a navigation controller, or do you have a stand-alone navigation bar? – rdelmar Oct 28 '13 at 05:57
  • 1
    The title might be misleading but it's actually the 'moving up' animation that the navigationbar automatically does instead of just staying there. This happens when using a navigationcontroller, I have the same problem. – Bob de Graaf Oct 28 '13 at 08:14
  • If anyone still has this problem, [this](https://stackoverflow.com/a/59136901/14351818) (adjusting `additionalSafeAreaInsets`) was the only thing that worked for me. – aheze Jan 30 '21 at 17:42

2 Answers2

0

I had the same problem, and could fix it changing windowLevel to UIWindowLevelStatusBar

Igor Palaguta
  • 3,579
  • 2
  • 20
  • 32
0

You can do this by

  1. moving the complete view of the view controller downward by default to a 20px lowered position, matching the height of the status bar (i.e., it will stay the same no matter if the status bar is displayed or not). You do this by changing the frame's y position and height.
  2. fixing the most likely unwanted black bar that you now have at the top by changing UIWindow.backgroundColor to whatever color you prefer (white in the normal case).

I just implemented this solution after numerous failed attempts of fixing the stutter that you get when switching between view controllers where one displays a status bar and another does not. This is the best solution I've found.

I did 1. in a subclass of UINavigationController. I assume this is your best option to stay consistent when walking through a navigation controllers sub view controllers. I did not test the other option though (putting it directly in the sub VC).

Why does this work and why is this the best way to go:

The navigation bar is actually always 44 points high (as commenters already mentioned), but the 20 point status bar pushes it down. Pushing the whole view for this same amount (20) down, ensures the most consistent behavior. Whenever you try to directly manipulate the UINavigationBar, iOS will go to great length to reverse this change.

Thomas Köhn
  • 123
  • 7