保持UINavigationBar相同的大小,同时隐藏状态栏 [英] Keeping UINavigationBar at same size while hiding status bar

查看:145
本文介绍了保持UINavigationBar相同的大小,同时隐藏状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试保持 UINavigationBar 在调用 setNeedsStatusBarAppearanceUpdate 时移动/调整大小。



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



任何帮助都将不胜感激!



UPDATE :我能够通过创建一个新的 UIWindow

    解决方案

    >
  1. 将视图控制器的完整视图默认向下移动到一个20px的下降位置,与状态栏的高度相匹配(即,无论是否显示状态栏,都将保持不变)。

  2. 通过将UIWindow.backgroundColor更改为您喜欢的任何颜色,固定现在顶部的最可能不需要的黑条(白色


  3. 我刚刚实现了这个解决方案后,大量的失败尝试修复你在视图控制器之间切换时得到的口吃一个显示状态栏,另一个不显示。这是我发现的最好的解决方案。



    我在UINavigationController的子类中做了。我认为这是你走在导航控制器子视图控制器时保持一致的最佳选择。我没有测试其他选项(把它直接在子VC)。



    为什么这是工作,为什么这是最好的方法:



    导航栏实际上总是44点高(如已经提到的评论者),但20点状态栏将其向下推。将该相同量(20)的整个视图向下推,确保最一致的行为。每当你尝试直接操纵UINavigationBar,iOS将会很大的时间来扭转这种变化。


    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.

    解决方案

    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.

    这篇关于保持UINavigationBar相同的大小,同时隐藏状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆