wkwebView 新增 進度條
// 進度條 的 progress
let progress: CAShapeLayer = {
let shape = CAShapeLayer()
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 1.5))
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 1.5))
shape.path = path.cgPath
// 進度條顏色
shape.strokeColor = UIColor(102, 153, 255).cgColor
shape.fillColor = UIColor.clear.cgColor
shape.strokeStart = 0
shape.strokeEnd = 0
shape.lineWidth = 3
shape.fillRule = kCAFillRuleNonZero
shape.lineCap = kCALineCapRound
return shape
}()
在viewdidload 裡面 觀察webView
webView.addObserver(self, forKeyPath: obk1, options: .new, context: nil)
webView.addObserver(self, forKeyPath: obk2, options: .new, context: nil)
// 把進度條layer 加到底層的的layer上
view.layer.addSublayer(progress)
// 然後在有新值變化的時候改變 起點位置 和終點位置就好了
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let keyPath = keyPath, let change = change else {return}
switch keyPath {
case obk1:
if let val = change[NSKeyValueChangeKey.newKey] as? Bool, !val {
delay(seconds: 0.2, completion: {
self.progress.opacity = 0
})
}
case obk2:
if let val = change[NSKeyValueChangeKey.newKey] as? CGFloat {
progress.strokeEnd = val
}
default:break
}
}
相關文章
- iOS WKWebView新增進度條02iOSWebView
- 【新特性速遞】進度條,進度條,進度條
- iOS UIWebView載入時新增進度條01iOSUIWebView
- 用 jQuery 和 Bootstrap 在 WordPress 中新增進度條jQueryboot
- WKWebView 獲取標題+進度條+常用代理方法以及native相容處理WebView
- ajax進度條 非同步下載進度條非同步
- iOS WKWebView UI增強(上拉重新整理,JS互動,載入進度條)iOSWebViewUIJS
- iOS WKWebView新增CookieiOSWebViewCookie
- Qt 進度條QT
- C# 下載帶進度條程式碼(普通進度條)C#
- HTML <progress> 進度條HTML
- canvas 畫進度條Canvas
- wxWidgets進度條
- 自定義進度條
- 學習進度條
- 簡單進度條
- Python進度條技巧Python
- 自定義view - 進度條View
- 自定義進度條列表
- iOS 自定義進度條iOS
- jquery ui進度條 progressbarjQueryUI
- Bootstrap學習 進度條boot
- 0528學習進度條
- c#進度條progressbarC#
- Linux 進度條(非100%)列出unzip進度Linux
- Android花樣loading進度條(三)-配文字環形進度條Android
- IOS 進階之 WKWebViewiOSWebView
- golang 進度條功能實現Golang
- Flutter 波浪圓形進度條Flutter
- 橡皮筋進度條ElasticProgressBarAST
- clip實現圓環進度條
- jQuery 進度條效果程式碼jQuery
- 命令列進度條實現命令列
- 自定義圓形進度條
- canvas環形進度條效果Canvas
- ios自定義圓環進度條iOS
- Android - 蝸牛進度條Android
- CSS快遞進度條效果CSS