如何在webview打开/显示之前刷新/加载我的.html页面的所有内容?
这是我的代码:
class ContactViewController: UIViewController {
@IBOutlet weak var AboutWebView: WKWebView!
let url = URLAddress()
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.myfakeurl.com/about.html")
let request = URLRequest(url: url!)
AboutWebView.load(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
我如何使用我的代码进行调整?
答案 0 :(得分:0)
只需隐藏网页视图,直至其完全加载并在webView(_:didFinish:)
中显示。
请注意,您应该将视图控制器符合WKNavigationDelegate
。
class ContactViewController: UIViewController, WKNavigationDelegate {
override func viewDidLoad() {
[...]
aboutWebView.navigationDelegate = self
aboutWebView.isHidden = true
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.isHidden = false
}
}