如何将视图高度调整到 iOS 中的导航栏下方?

How can I Adjust view height to be below navigation bar in iOS?

我在代码中创建了一个 WKWebView 并将其添加到我的视图中。

override func loadView() {
    webView = WKWebView()
    webView.navigationDelegate = self
    view = webView
}

当网页打开时,我可以看到之前视图中的导航栏遮挡了我的某些网页。

如何调整代码中的视图,使我的网页显示在导航栏下方?

您应该为您的 webview 添加一个顶部约束并为其提供一个适合您的常量值(以防您想要添加边距)

    webView.translatesAutoresizingMaskIntoConstraints = false
    webView.topAnchor.constraint(equalTo: parentView.topAnchor, constant: 40).isActive = true

您还应该添加剩余的锚点值。

    webView.bottomAnchor.constraint(equalTo: parentView.bottomAnchor, constant: 0).isActive = true
    webView.trailingAnchor.constraint(equalTo: parentView.trailingAnchor, constant: 0).isActive = true
    webView.leadingAnchor.constraint(equalTo: parentView.leadingAnchor, constant: 0).isActive = true