【发布时间】:2017-12-06 11:42:45
【问题描述】:
This is the configuration of the storyboard: see the image
*看上面的图片链接,支持iOS9到iOS11
以下是工作代码解决方案:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, UIApplicationDelegate, WKNavigationDelegate {
@IBOutlet weak var webViewContainer: UIView!
let requestURLString = "http://google.com/“
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
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)
webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: webViewContainer.rightAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: webViewContainer.leftAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor).isActive = true
webView.heightAnchor.constraint(equalTo: webViewContainer.heightAnchor).isActive = true
webView.uiDelegate = self
webView.navigationDelegate = self
webView.scrollView.bounces = false
self.openUrl()
}
func openUrl() {
let url = URL (string: requestURLString)
let request = URLRequest(url: url!)
webView.load(request)
}
}
我正在分享包含此项目的链接: https://github.com/kiril6/iPhoneX-webkitWebView
【问题讨论】:
-
只需拖放您的 webKit 并添加约束 0,0,0,0 作为顶部、前导、尾随和底部。它可以在 iPhone X 上运行
-
是的,但问题是我支持 iOS 9 及更高版本,无法在情节提要中添加 webkit web 视图 - 给出错误,但可能仅适用于 11 及更高版本
标签: swift ios11 iphone-x safearealayoutguide xcode9.2