WKWebView - Ignore the right "safe area inset" in landscape view

Viewed 403

I am fairly new to iOS development and I'm using a WKWebView to render my website. I am trying to add some constraints but want to ignore the right "safe area inset" in landscape view as marked in the screenshot.

Here is the screenshot.

enter image description here

Here is the code.

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])
}

Any help will be appreciated.

1 Answers

Use size classes and change the constraint like below in the image

enter image description here

Related