这是我的代码:
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var progressView: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
webView.uiDelegate = self
webView.navigationDelegate = self
webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if (keyPath == "estimatedProgress") {
progressView.setProgress(Float(webView.estimatedProgress), animated: true)
print(webView.estimatedProgress)
}
}
但是estimatedProgress只显示了两个浮点数(0.1和1.0),我认为它没有起作用。我使用了Alamofire进度,并且在毫秒级别下改变了它,使我的UI更好,但是这段代码不正常工作...
有人可以帮我处理webView的进度吗?