*看上面的图片链接,支持iOS9到iOS11
\n\n以下是工作代码解决方案:
\n\nimport UIKit\nimport WebKit\n\nclass ViewController: UIViewController, WKUIDelegate, UIApplicationDelegate, WKNavigationDelegate {\n\n @IBOutlet weak var webViewContainer: UIView!\n\n let requestURLString = "http://google.com/\xe2\x80\x9c\n\n var webView: WKWebView!\n\n override func viewDidLoad() { \n\n super.viewDidLoad()\n let webConfiguration = WKWebViewConfiguration()\n\n let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.webViewContainer.frame.size.height))\n self.webView = WKWebView (frame: customFrame , configuration: webConfiguration)\n webView.translatesAutoresizingMaskIntoConstraints = false\n self.webViewContainer.addSubview(webView)\n webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor).isActive = true\n webView.rightAnchor.constraint(equalTo: webViewContainer.rightAnchor).isActive = true\n webView.leftAnchor.constraint(equalTo: webViewContainer.leftAnchor).isActive = true\n webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor).isActive = true\n webView.heightAnchor.constraint(equalTo: webViewContainer.heightAnchor).isActive = true \n\n …Run Code Online (Sandbox Code Playgroud)