【问题标题】:WKWebView - Ignore the right "safe area inset" in landscape viewWKWebView - 在横向视图中忽略正确的“安全区域插图”
【发布时间】:2021-09-13 21:12:45
【问题描述】:

我对 iOS 开发相当陌生,我正在使用 WKWebView 来呈现我的网站。我正在尝试添加一些约束,但想忽略屏幕截图中标记的横向视图中正确的“安全区域插图”。

这是截图。

这里是代码。

let webConfiguration = WKWebViewConfiguration()

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.webViewContainer.frame.size.height))
     
self.webView = WKWebView (frame: customFrame , configuration: webConfiguration)
       webView.translatesAutoresizingMaskIntoConstraints = false
       self.webViewContainer.addSubview(webView)
    
    
addConstraints(to: webView, with: webViewContainer)

func addConstraints(to webView: UIView, with superView: UIView) {
    webView.translatesAutoresizingMaskIntoConstraints = false
    let leadingConstraint = NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: superView, attribute: .leading, multiplier: 1, constant: 0)
    let trailingConstraint = NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: superView, attribute: .trailing, multiplier: 1, constant: 0)
    let topConstraint = NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: superView, attribute: .top, multiplier: 1, constant: 0)
    let bottomConstraint = NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: superView, attribute: .bottom, multiplier: 1, constant: 0)
    superView.addConstraints([leadingConstraint, trailingConstraint, topConstraint, bottomConstraint])
}

任何帮助将不胜感激。

【问题讨论】:

    标签: ios swift wkwebview


    【解决方案1】:

    使用尺寸等级并更改约束,如下图所示

    【讨论】:

    • 不幸的是,我无法使用情节提要添加约束。可以发给我对应的 Swift 代码吗?
    • 请将对应的代码行发给我。
    猜你喜欢
    • 1970-01-01
    • 2019-10-17
    • 2022-08-19
    • 2022-01-20
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    相关资源
    最近更新 更多