ios - UINavigationController 栏覆盖其 uiviewcontroller 的内容

标签 ios uiviewcontroller uinavigationcontroller uitoolbar nslayoutconstraint

我有一个 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 被部分遮盖了。

根据apple documentation

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/

相关文章:

ios - 如何列出所有事件的(未解除分配的)UIViewControllers?

iphone - xcode:如何在使用 AVFoundation 录制音频后保存音频文件

ios - iPhone 5 连接到 Mac,开发菜单选项显示设备为 "Use for development"

iphone - AVPlayerItem 失败并显示 AVStatusFailed 和错误代码 "Cannot Decode"

ios - 如何初始化一个 Nib 为 Storyboard 的 UIViewController

swift - 为什么我得到这个字符串值是 nil?

ios - ios 设备可以连接外接有线摄像头吗?

ios - 通过 NavC-SWRevealviewController-NavY 将数据从 VC 传递到 VC

uinavigationcontroller - 在CCLayer中添加UINavigationController

IOS - Swift - UINavigationController.hidesBarsOnSwipe 错误