带有导航项的自动布局

Autolayout with Navigation Item

我正在尝试通过自动布局将我的 UIImageView 固定到顶部,但不太了解如何将它固定到导航项本身。

原来是视图本身

这行怎么写才正确?

imageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 10) = true

导航栏自动添加为安全区域的一部分。您需要像这样将视图的顶部固定到 safeAreaLayoutGuide:

imageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10) = true

标签栏也是如此。