我有一个 UIViewController,MyViewController,顶部有一个 UIToolbar。使用界面构建器,文档大纲如下所示:
View
- subview1
- subview2
- UIToolbar
- Bar Button Item1
- Bar Button Item2
- Bar Button Item3
我的应用程序中使用了 MyViewController。有时它在 UINavigationcontroller 中,有时它在 UIPopoverView 中。
当它出现在 UINavigationController 中时,导航栏会覆盖 UIToolbar 和 View 顶部附近的所有其他内容。在 this screenshot您可以看到 UIToolbar 被完全遮盖了,带有绿色灯泡图像的 UIButton 被部分遮盖了。
Any view that needs to be anchored to the top and just below the status bar (i.e. UIToolbar, UIButton, etc.) requires additional work for proper placement.
它继续提供一个解决方案,该解决方案仅使用约束将 VC 的内容向下移动 x 像素,在我的例子中是 UIToolbar。这似乎不是一个好的解决方案,因为它假定您始终希望将内容向下移动到导航栏下方。在我的例子中,我显然不这样做,因为 MyViewController 并不总是在 UINavigationController 中。当我使用这些文档中提供的约束解决方案时,在 MyViewController 不在 UINavigationController 中的所有情况下,UIToolbar 奇怪地从顶部向下 float x 像素。
在 UINavigationController 中应该如何显示 VC 的内容,我是否遗漏了什么?非常感谢。
最佳答案
在iOS7中,UINavigationBar有translucent
属性,UINavigationViewController的子VC的 View 默认在UINavigationBar下面。
如果你不需要这个半透明效果,可以使用下面的代码关闭这个属性。
self.navigationController.navigationBar.translucent = NO
您也可以使用@ldindu 的方式。
关于ios - UINavigationController 栏覆盖其 uiviewcontroller 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20809164/