在隐藏状态栏的同时保持UINavigationBar的大小相同

时间:2013-10-27 16:58:42

标签: ios iphone objective-c cocoa-touch

在调用UINavigationBar时,我一直试图阻止setNeedsStatusBarAppearanceUpdate移动/调整大小。

当状态栏隐藏动画时,我想将导航栏保持在64px的高度。

任何帮助将不胜感激!

更新:我能够通过创建新的UIWindow并覆盖状态栏来解决此问题。

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并且可以修复它将windowLevel更改为UIWindowLevelStatusBar

答案 1 :(得分: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.