如何自动将top space 给ios 中的导航栏?

How to give automatically top space to navigation bar in ios?

我有一个UIViewController。我正在为 iPhone 5 秒设计屏幕。我有一个 UIImageView 并且我将 top space 给了 20 个容器。我在 top.So 处也有 UINavigationBar 给出的 20 个 space 是不够的。 UIImageView 隐藏在 UINavigationBar 后面。我可以通过从顶部提供 much space 来解决这个问题。但在那种情况下,在设计时我的 UI 看起来不合适。那么有什么方法可以自动计算出UINavigationBar的space吗?

Attribute Inspector 中将 Top Bar 设置为 Translucent Navigation Bar 像这样

然后将imageView的Top Space设置为Top Layout Guide like,

将导航栏类型设置为不透明导航栏,这样它会在您的视图控制器中不透明 space 并在导航栏后显示您的视图内容 space 它们不会隐藏在导航栏内。

但是如果您将导航栏类型设置为半透明导航栏,那么您的内容将隐藏在导航栏内,因此请设置 "Opaque Navigation Bar" 类型。无需为此做任何其他事情。

希望对您有所帮助!