iOS实现微信网页进度条,WKWebview进度条的实现
2016-07-13 15:00
726 查看
实现微信网页进度条或者说就是webview的加载进度条的效果,主要代码如下:
一.第一步,添加观察者
[_webViewaddObserver:selfforKeyPath:@"estimatedProgress"options:NSKeyValueObservingOptionNewcontext:NULL];
_progressView = [[UIProgressViewalloc]
initWithFrame:CGRectMake(0,0,
kScreenWidth,3)];
_progressView.tintColor =kGlobalGoldColor;
_progressView.trackTintColor = [UIColorwhiteColor];
二.实现
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if ([keyPathisEqualToString:@"estimatedProgress"]) {
if (object ==_webView) {
[self.progressViewsetAlpha:1.0f];
[self.progressViewsetProgress:self.webView.estimatedProgressanimated:YES];
if(_webView.estimatedProgress >=1.0f)
{
[UIViewanimateWithDuration:0.3delay:0.3options:UIViewAnimationOptionCurveEaseOutanimations:^{
[self.progressViewsetAlpha:0.0f];
} completion:^(BOOL finished) {
[self.progressViewsetProgress:0.0fanimated:NO];
}];
}
}
else
{
[superobserveValueForKeyPath:keyPathofObject:object
change:changecontext:context];
}
}
}
三.移除观察者
- (void)dealloc
{
[_webViewremoveObserver:selfforKeyPath:@"estimatedProgress"];
}
以上就可以实现微信网页进度条的效果,颜色,尺寸自行设计即可
一.第一步,添加观察者
[_webViewaddObserver:selfforKeyPath:@"estimatedProgress"options:NSKeyValueObservingOptionNewcontext:NULL];
_progressView = [[UIProgressViewalloc]
initWithFrame:CGRectMake(0,0,
kScreenWidth,3)];
_progressView.tintColor =kGlobalGoldColor;
_progressView.trackTintColor = [UIColorwhiteColor];
二.实现
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if ([keyPathisEqualToString:@"estimatedProgress"]) {
if (object ==_webView) {
[self.progressViewsetAlpha:1.0f];
[self.progressViewsetProgress:self.webView.estimatedProgressanimated:YES];
if(_webView.estimatedProgress >=1.0f)
{
[UIViewanimateWithDuration:0.3delay:0.3options:UIViewAnimationOptionCurveEaseOutanimations:^{
[self.progressViewsetAlpha:0.0f];
} completion:^(BOOL finished) {
[self.progressViewsetProgress:0.0fanimated:NO];
}];
}
}
else
{
[superobserveValueForKeyPath:keyPathofObject:object
change:changecontext:context];
}
}
}
三.移除观察者
- (void)dealloc
{
[_webViewremoveObserver:selfforKeyPath:@"estimatedProgress"];
}
以上就可以实现微信网页进度条的效果,颜色,尺寸自行设计即可
相关文章推荐
- Android 检查当前设备是否有摄像头
- 使用TexturePacker生成png和plist,在Cocos2dx中使用plist和png
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
- 微信支付注意要点(补充ING)
- canvas实现移动端和PC端刮刮卡效果
- Android仿腾讯QQ实现滑动删除 附源码下载
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android 按钮点击变换颜色
- Android横竖屏切换总结
- 从服务端架构设计角度,深入理解大型APP架构升级
- Android播放远程非流MP4文件
- Android属性动画完全解析(上),初识属性动画的基本用法
- Android WebView与javaScript之间的交互
- iOS开发支付集成之银联支付
- Android 热修复 - AndFix 使用心得
- 验证出错,错误码:230,请AndroidManifest.xml文件中检查 kye 设置。
- swift(六)函数的简单使用
- 谈谈Android 6.0运行时权限理解
- Android 自定义Dialog 实例
- iOS开发支付集成之微信支付