这是我的代码:
@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)
}
}
Run Code Online (Sandbox Code Playgroud)
但是,估计进度只显示两个浮点数(0.1和1.0)而且我觉得它不起作用.我使用了Alamofire的进度,它改变了几毫秒,使我的UI更好,但这段代码不能正常工作......
有谁可以帮助我进行webView的进展?