WkwebView 加载进度条过度动画

/// 进度条属性:
internal var progress:UIProgressView = UIProgressView(progressViewStyle: UIProgressViewStyle.bar)

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if let web = (object! as? WKWebView) {
            
            if(keyPath! == "title"){
                //获取标题
                self.title = web.title!
            }
            else if(keyPath! == "estimatedProgress") {

                //加载进度
                self.progress.isHidden = self.webView?.estimatedProgress == 1
                UIView .animate(withDuration: 0.8, animations: {

//                    self.progress.setProgress(Float(Double(SCREEN_WIDTH) * self.webView?.estimatedProgress ?? 0.0, animated: true))
                    self.progress.setProgress(Float(SCREEN_WIDTH * CGFloat(self.webView?.estimatedProgress ?? 0)), animated: true)
                }) { (fished) in
                    if self.webView?.estimatedProgress == 1 {
                        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.3 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
                            
                        })
                    }
                }
            }
        }
    }

你可能感兴趣的:(WkwebView 加载进度条过度动画)