在打开/加载WKWebView之前加载/刷新它

时间:2017-11-07 21:39:53

标签: ios swift wkwebview

如何在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()
    }




}

我如何使用我的代码进行调整?

1 个答案:

答案 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
    }
}