WKwebview没有显示活动指标

问题描述 投票:0回答:1

我想在WKWebView中加载一个网页。它实际上工作正常。但是,我一直在让进度指示器(UIActivityIndicaatorView())显示出来。我无法弄清楚出了什么问题。我尝试了很多解决方案。请帮忙

    var activityIndicator:UIActivityIndicatorView = UIActivityIndicatorView()
    var webView:WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setting up webview
        let webConfiguraton = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguraton)
        webView.uiDelegate = self
        view.addSubview(webView)
        let myURL = URL(string:"link")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
        webView.addObserver(self, forKeyPath: #keyPath(WKWebView.isLoading), options: .new, context: nil)
        // setting up activity indicator
        activityIndicator.center = self.view.center
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        // Do any additional setup after loading the view.
    }

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath == "loading"{
            if webView.isLoading{

            } else {

            }
        }
    }
ios swift progress
1个回答
0
投票

WKWebView似乎没有出现因为你将它的frame大小设置为.zero。您可以尝试设置它:

webView = WKWebView(frame: self.view.frame, configuration: webConfiguraton)
© www.soinside.com 2019 - 2024. All rights reserved.