//添加观察者模式
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
#pragma mark - 监听加载进度
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) {
if (object ==self.webView) {
[_progressView setAlpha:1.0f];
[_progressView setProgress:self.webView.estimatedProgress animated:YES];
if(self.webView.estimatedProgress >=1.0f) {
[UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
[_progressView setAlpha:0.0f];
} completion:^(BOOL finished) {
[_progressView setProgress:0.0f animated:NO];
}];
}
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
}
- (void)dealloc{
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
}
iOS WKWebView监听网页加载进度
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- WKWebView的进度条WKWebView的回退上级网页WKWebView的获取网页标题 [获取系统返回按钮的点...
- @property (weak, nonatomic) CALayer *progresslayer;//进度条 ...
- WKWebView是iOS8 WebKit框架下控件,WKWebView 的estimatedProgress是当...
- 一、效果展示 二、主要步骤 1.添加UIProgressView属性 2.初始化progressView 3.添加...
- 一、WKWebView 使用WKWebView替换UIWebView可以大量减少运行内存。用法与UIWebView...