wkwebview 在横向模式下无法正确显示

wkwebview not showing properly in landscape mode

这是我的故事板的样子

下面是我的代码

class ViewController: UIViewController,WKNavigationDelegate {//WKUIDelegate

@IBOutlet weak var webContainer: UIView!
var webView : WKWebView!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    initMyWeb()
}

func initMyWeb() -> Void {


    let myBlog = "https://google.com"
    let myURL = URL(string: myBlog)
    let request = URLRequest(url: myURL!)

    // init and load request in webview.
    webView = WKWebView(frame: self.webContainer.frame)
    webView.navigationDelegate = self
    webView.load(request)
    self.webContainer.addSubview(webView)
    self.webContainer.sendSubview(toBack: webView)
}


//MARK:- WKNavigationDelegate

func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
    print(error.localizedDescription)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    print("Start to load")
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    print("finish to load")
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    webView.frame = self.webContainer.frame
}

当我 运行 它处于横向模式时,它看起来像这样

我的问题是:如何让它横屏适配全屏?我给它的大小等于 webContainer view

试试这个

webView = WKWebView(frame: self.webContainer.frame)
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
webView.navigationDelegate = self
webView.load(request)