├── .gitignore ├── README.md └── WebViewProgressDemo ├── WebProgressView ├── YHWebViewProgress.h ├── YHWebViewProgress.m ├── YHWebViewProgressView.h ├── YHWebViewProgressView.m └── YHWebViewProgressViewProtocol.h ├── WebViewProgressDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── WebViewProgressDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── FirstViewController.h ├── FirstViewController.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── first.imageset │ │ ├── Contents.json │ │ └── first.pdf │ └── second.imageset │ │ ├── Contents.json │ │ └── second.pdf ├── Info.plist ├── SecondViewController.h ├── SecondViewController.m ├── WebProgressView │ ├── YHWebViewProgress.h │ ├── YHWebViewProgress.m │ ├── YHWebViewProgressView.h │ ├── YHWebViewProgressView.m │ └── YHWebViewProgressViewProtocol.h └── main.m └── WebViewProgressDemoTests ├── Info.plist └── WebViewProgressDemoTests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebViewProgressView 2 | WebView进度条 3 | 4 | 5 | ### How To Use 6 | * **UIWebView模式:** 7 | 8 | ```objc 9 | // 创建进度条代理,用于处理进度控制 10 | _progressProxy = [[YHWebViewProgress alloc] init]; 11 | 12 | // 创建进度条 13 | YHWebViewProgressView *progressView = [[YHWebViewProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), CGRectGetWidth(self.view.bounds), 4)]; 14 | progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin; 15 | 16 | // 设置进度条 17 | self.progressProxy.progressView = progressView; 18 | // 将UIWebView代理指向YHWebViewProgress 19 | self.webView.delegate = self.progressProxy; 20 | // 设置webview代理转发到self(可选) 21 | self.progressProxy.webViewProxy = self; 22 | 23 | // 添加到视图 24 | [self.view addSubview:progressView]; 25 | ``` 26 | 27 | * **WKWebView模式:** 28 | 29 | ```objc 30 | // 创建进度条 31 | YHWebViewProgressView *progressView = [[YHWebViewProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), CGRectGetWidth(self.view.bounds), 4)]; 32 | progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin; 33 | // 指定WKWebView对象来监听进度 34 | [progressView useWkWebView:self.webView]; 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebProgressView/YHWebViewProgress.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgress.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "YHWebViewProgressViewProtocol.h" 11 | 12 | @interface YHWebViewProgress : NSObject 13 | 14 | @property (readonly, nonatomic) float progress; 15 | @property (strong, nonatomic) UIView *progressView; 16 | @property (weak, nonatomic) id webViewProxy; 17 | 18 | - (void)reset; 19 | 20 | 21 | // 外部使用时,不要调用该方法 22 | - (BOOL)checkIfRPCURL:(NSURLRequest *)request; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebProgressView/YHWebViewProgress.m: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgress.m 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import "YHWebViewProgress.h" 10 | 11 | NSString *completeRPCURLPath = @"/yhwebviewprogressproxy/complete"; 12 | 13 | static const float YHWebViewProgressInitialValue = 0.7f; 14 | static const float YHWebViewProgressInteractiveValue = 0.9f; 15 | static const float YHWebViewProgressFinalProgressValue = 0.9f; 16 | 17 | @interface YHWebViewProgress () 18 | @property (nonatomic) NSUInteger loadingCount; 19 | @property (nonatomic) NSUInteger maxLoadCount; 20 | @property (strong, nonatomic) NSURL *currentURL; 21 | @property (nonatomic) BOOL interactive; 22 | 23 | @property (nonatomic) float progress; 24 | 25 | @end 26 | 27 | @implementation YHWebViewProgress 28 | 29 | - (instancetype)init 30 | { 31 | self = [super init]; 32 | if (self) { 33 | _maxLoadCount = _loadingCount = 0; 34 | _interactive = NO; 35 | } 36 | 37 | return self; 38 | } 39 | 40 | - (void)dealloc 41 | { 42 | 43 | } 44 | 45 | - (void)startProgress 46 | { 47 | if (self.progress < YHWebViewProgressInitialValue) { 48 | [self setProgress:YHWebViewProgressInitialValue]; 49 | } 50 | } 51 | 52 | - (void)incrementProgress 53 | { 54 | float progress = self.progress; 55 | float maxProgress = self.interactive?YHWebViewProgressFinalProgressValue:YHWebViewProgressInteractiveValue; 56 | float remainPercent = (float)self.loadingCount/self.maxLoadCount; 57 | float increment = (maxProgress-progress) * remainPercent; 58 | progress += increment; 59 | progress = fminf(progress, maxProgress); 60 | [self setProgress:progress]; 61 | } 62 | 63 | - (void)completeProgress 64 | { 65 | [self setProgress:1.f]; 66 | } 67 | 68 | - (void)setProgress:(float)progress 69 | { 70 | if (progress > _progress || progress == 0) { 71 | _progress = progress; 72 | 73 | if (self.progressView) { 74 | [self.progressView setProgress:progress animated:YES]; 75 | } 76 | } 77 | } 78 | 79 | - (void)reset 80 | { 81 | self.maxLoadCount = self.loadingCount = 0; 82 | self.interactive = NO; 83 | [self setProgress:0.f]; 84 | } 85 | 86 | - (BOOL)checkIfRPCURL:(NSURLRequest *)request 87 | { 88 | if ([request.URL.path isEqualToString:completeRPCURLPath]) { 89 | [self completeProgress]; 90 | return YES; 91 | } 92 | 93 | return NO; 94 | } 95 | 96 | #pragma mark - UIWebViewDelegate 97 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 98 | { 99 | BOOL ret = YES; 100 | 101 | if (self.webViewProxy) { 102 | if ([self checkIfRPCURL:request]) { 103 | return NO; 104 | } 105 | 106 | if ([self.webViewProxy respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { 107 | ret = [self.webViewProxy webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; 108 | } 109 | } 110 | 111 | BOOL isFragmentJump = NO; 112 | if (request.URL.fragment) { 113 | NSString *nonFragmentURL = [request.URL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:request.URL.fragment] withString:@""]; 114 | isFragmentJump = [nonFragmentURL isEqualToString:webView.request.URL.absoluteString]; 115 | } 116 | 117 | BOOL isTopLevelNavigation = [request.mainDocumentURL isEqual:request.URL]; 118 | 119 | BOOL isHTTP = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"]; 120 | if (ret && !isFragmentJump && isHTTP && isTopLevelNavigation) { 121 | self.currentURL = request.URL; 122 | [self reset]; 123 | } 124 | 125 | return ret; 126 | } 127 | 128 | - (void)webViewDidStartLoad:(UIWebView *)webView 129 | { 130 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webViewDidStartLoad:)]) { 131 | [self.webViewProxy webViewDidStartLoad:webView]; 132 | } 133 | 134 | self.loadingCount++; 135 | 136 | self.maxLoadCount = fmax(self.loadingCount, self.loadingCount); 137 | 138 | [self startProgress]; 139 | } 140 | 141 | - (void)webViewDidFinishLoad:(UIWebView *)webView 142 | { 143 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webViewDidFinishLoad:)]) { 144 | [self.webViewProxy webViewDidFinishLoad:webView]; 145 | } 146 | 147 | self.loadingCount--; 148 | [self incrementProgress]; 149 | 150 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 151 | 152 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 153 | if (interactive) { 154 | self.interactive = interactive; 155 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", 156 | webView.request.mainDocumentURL.scheme, 157 | webView.request.mainDocumentURL.host, 158 | completeRPCURLPath]; 159 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 160 | } 161 | 162 | BOOL isNotRedirect = self.currentURL && [self.currentURL isEqual:webView.request.mainDocumentURL]; 163 | BOOL complete = [readyState isEqualToString:@"complete"]; 164 | if (complete && isNotRedirect) { 165 | [self completeProgress]; 166 | } 167 | } 168 | 169 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 170 | { 171 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 172 | [self.webViewProxy webView:webView didFailLoadWithError:error]; 173 | } 174 | 175 | _loadingCount--; 176 | [self incrementProgress]; 177 | 178 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 179 | 180 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 181 | if (interactive) { 182 | self.interactive = YES; 183 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", webView.request.mainDocumentURL.scheme, webView.request.mainDocumentURL.host, completeRPCURLPath]; 184 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 185 | } 186 | 187 | BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL]; 188 | BOOL complete = [readyState isEqualToString:@"complete"]; 189 | if ((complete && isNotRedirect) || error) { 190 | [self completeProgress]; 191 | } 192 | } 193 | 194 | #pragma mark - Method Forwarding 195 | - (BOOL)respondsToSelector:(SEL)aSelector 196 | { 197 | if ([super respondsToSelector:aSelector]) { 198 | return YES; 199 | } 200 | 201 | if ([self.webViewProxy respondsToSelector:aSelector]) { 202 | return YES; 203 | } 204 | 205 | return NO; 206 | } 207 | 208 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 209 | { 210 | NSMethodSignature *signature = [super methodSignatureForSelector:aSelector]; 211 | if (!signature) { 212 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:aSelector]) { 213 | return [(NSObject *)self.webViewProxy methodSignatureForSelector:aSelector]; 214 | } 215 | } 216 | 217 | return signature; 218 | } 219 | 220 | - (void)forwardInvocation:(NSInvocation *)anInvocation 221 | { 222 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:[anInvocation selector]]) { 223 | [anInvocation invokeWithTarget:self.webViewProxy]; 224 | } 225 | } 226 | 227 | @end 228 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebProgressView/YHWebViewProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressView.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "YHWebViewProgressViewProtocol.h" 11 | @import WebKit; 12 | 13 | @interface YHWebViewProgressView : UIView 14 | 15 | @property (nonatomic) float progress; 16 | 17 | @property (readonly, nonatomic) UIView *progressBarView; 18 | @property (nonatomic) NSTimeInterval barAnimationDuration;// default 0.5 19 | @property (nonatomic) NSTimeInterval fadeAnimationDuration;// default 0.27 20 | @property (copy, nonatomic) UIColor *progressBarColor; 21 | 22 | - (void)useWkWebView:(WKWebView *)webView; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebProgressView/YHWebViewProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressView.m 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import "YHWebViewProgressView.h" 10 | 11 | #define kAnimationDurationMultiplier (1.8) 12 | 13 | @interface YHWebViewProgressView () 14 | @property (nonatomic) BOOL isWkWebView; 15 | @end 16 | 17 | @implementation YHWebViewProgressView 18 | 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | self = [super initWithFrame:frame]; 22 | if (self) { 23 | [self configureViews]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (void)awakeFromNib 30 | { 31 | [super awakeFromNib]; 32 | [self configureViews]; 33 | } 34 | 35 | - (void)dealloc 36 | { 37 | 38 | } 39 | 40 | - (void)configureViews 41 | { 42 | self.isWkWebView = NO; 43 | self.userInteractionEnabled = NO; 44 | self.clipsToBounds = YES; 45 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 46 | _progressBarView = [[UIView alloc] initWithFrame:self.bounds]; 47 | _progressBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 48 | UIColor *tintColor = [UIColor colorWithRed:22/255.f 49 | green:126/255.f 50 | blue:251/255.f 51 | alpha:1.f]; 52 | 53 | if ([UIApplication.sharedApplication.delegate.window respondsToSelector:@selector(setTintColor:)] 54 | && UIApplication.sharedApplication.delegate.window.tintColor) { 55 | tintColor = UIApplication.sharedApplication.delegate.window.tintColor; 56 | } 57 | 58 | _progressBarView.backgroundColor = tintColor; 59 | [self addSubview:_progressBarView]; 60 | 61 | _barAnimationDuration = 0.5f; 62 | _fadeAnimationDuration = 0.27f; 63 | 64 | [self setProgress:0.f]; 65 | } 66 | 67 | - (void)setProgressBarColor:(UIColor *)progressBarColor 68 | { 69 | _progressBarView.backgroundColor = progressBarColor; 70 | } 71 | 72 | - (UIColor *)progressBarColor 73 | { 74 | return self.progressBarView.backgroundColor; 75 | } 76 | 77 | - (void)setProgress:(float)progress 78 | { 79 | [self setProgress:progress animated:NO]; 80 | } 81 | 82 | - (void)useWkWebView:(WKWebView *)webView 83 | { 84 | if (!webView) { 85 | return; 86 | } 87 | self.isWkWebView = YES; 88 | [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; 89 | } 90 | 91 | - (void)setProgress:(float)progress animated:(BOOL)animated 92 | { 93 | BOOL isGrowing = progress > 0.f; 94 | 95 | CGFloat originX = -CGRectGetWidth(self.bounds)/2; 96 | CGPoint positionBegin = CGPointMake(originX+_progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2); 97 | CGPoint positionEnd = CGPointMake(originX+progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2); 98 | 99 | if (progress < _progress) { 100 | animated = NO; 101 | } 102 | 103 | if (!isGrowing) { 104 | if (animated) { 105 | [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f 106 | delay:0 107 | options:UIViewAnimationOptionCurveEaseInOut 108 | animations:^{ 109 | self.progressBarView.center = positionEnd; 110 | self.progressBarView.alpha = 1.f; 111 | } completion:^(BOOL finished) {}]; 112 | } else { 113 | self.progressBarView.alpha = 1.f; 114 | self.progressBarView.center = positionEnd; 115 | } 116 | } else { 117 | [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f 118 | delay:0 119 | options:UIViewAnimationOptionCurveEaseInOut 120 | animations:^{ 121 | self.progressBarView.alpha = 1.f; 122 | } completion:^(BOOL finished) {}]; 123 | 124 | if (animated) { 125 | CAAnimation *animationBounds = nil; 126 | 127 | if (progress < 1) { 128 | if (_progress > 0.01 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) { 129 | positionBegin = [self.progressBarView.layer.presentationLayer position]; 130 | self.progressBarView.layer.position = positionBegin; 131 | [self.progressBarView.layer removeAnimationForKey:@"positionAnimation"]; 132 | } 133 | 134 | CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 135 | keyFrameAnimation.duration = kAnimationDurationMultiplier*(progress-_progress)*10; 136 | keyFrameAnimation.keyTimes = @[ @0, @.3, @1 ]; 137 | keyFrameAnimation.values = @[ [NSValue valueWithCGPoint:positionBegin], 138 | [NSValue valueWithCGPoint:CGPointMake(positionBegin.x+(positionEnd.x-positionBegin.x)*0.9, positionEnd.y)], 139 | [NSValue valueWithCGPoint:positionEnd] ]; 140 | keyFrameAnimation.timingFunctions = @[ [CAMediaTimingFunction functionWithControlPoints: 0.092 : 0.000 : 0.618 : 1.000], 141 | [CAMediaTimingFunction functionWithControlPoints: 0.000 : 0.688 : 0.479 : 1.000] ]; 142 | 143 | animationBounds = keyFrameAnimation; 144 | } else { 145 | if (_progress > 0.05 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) { 146 | positionBegin = [self.progressBarView.layer.presentationLayer position]; 147 | self.progressBarView.layer.position = positionBegin; 148 | [self.progressBarView.layer removeAnimationForKey:@"positionAnimation"]; 149 | } 150 | CABasicAnimation *basicAnimationBounds = [CABasicAnimation animationWithKeyPath:@"position"]; 151 | basicAnimationBounds.fromValue = [NSValue valueWithCGPoint:positionBegin]; 152 | basicAnimationBounds.toValue = [NSValue valueWithCGPoint:positionEnd]; 153 | basicAnimationBounds.duration = self.barAnimationDuration; 154 | basicAnimationBounds.timingFunction = [CAMediaTimingFunction functionWithControlPoints: 0.486 : 0.056 : 0.778 : 0.480]; 155 | 156 | basicAnimationBounds.delegate = self; 157 | 158 | animationBounds = basicAnimationBounds; 159 | } 160 | 161 | [self.progressBarView.layer addAnimation:animationBounds forKey:@"positionAnimation"]; 162 | self.progressBarView.layer.position = positionEnd; 163 | 164 | } else { 165 | self.progressBarView.layer.position = positionEnd; 166 | } 167 | } 168 | 169 | _progress = progress; 170 | } 171 | 172 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 173 | { 174 | _progress = 0.f; 175 | CABasicAnimation *animationOpacity = [CABasicAnimation animationWithKeyPath:@"opacity"]; 176 | animationOpacity.fromValue = @1; 177 | animationOpacity.toValue = @0; 178 | animationOpacity.duration = self.fadeAnimationDuration; 179 | animationOpacity.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 180 | [self.progressBarView.layer addAnimation:animationOpacity forKey:@"opacityAnimation"]; 181 | self.progressBarView.layer.opacity = 0; 182 | } 183 | 184 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 185 | { 186 | [self setProgress:[change[@"new"] doubleValue] animated:YES]; 187 | } 188 | 189 | @end 190 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebProgressView/YHWebViewProgressViewProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressViewProtocol.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | @protocol YHWebViewProgressViewProtocol 10 | @required 11 | - (void)setProgress:(float)progress animated:(BOOL)animated; 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5035D5751AC540BE00E257B4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D5741AC540BE00E257B4 /* main.m */; }; 11 | 5035D5781AC540BE00E257B4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D5771AC540BE00E257B4 /* AppDelegate.m */; }; 12 | 5035D57B1AC540BE00E257B4 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D57A1AC540BE00E257B4 /* FirstViewController.m */; }; 13 | 5035D57E1AC540BE00E257B4 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D57D1AC540BE00E257B4 /* SecondViewController.m */; }; 14 | 5035D5811AC540BE00E257B4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5035D57F1AC540BE00E257B4 /* Main.storyboard */; }; 15 | 5035D5831AC540BE00E257B4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5035D5821AC540BE00E257B4 /* Images.xcassets */; }; 16 | 5035D5861AC540BE00E257B4 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5035D5841AC540BE00E257B4 /* LaunchScreen.xib */; }; 17 | 5035D5921AC540BE00E257B4 /* WebViewProgressDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D5911AC540BE00E257B4 /* WebViewProgressDemoTests.m */; }; 18 | 5035D5A11AC5426A00E257B4 /* YHWebViewProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D59D1AC5426A00E257B4 /* YHWebViewProgress.m */; }; 19 | 5035D5A21AC5426A00E257B4 /* YHWebViewProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5035D59F1AC5426A00E257B4 /* YHWebViewProgressView.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 5035D58C1AC540BE00E257B4 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 5035D5671AC540BE00E257B4 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 5035D56E1AC540BE00E257B4; 28 | remoteInfo = WebViewProgressDemo; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 5035D56F1AC540BE00E257B4 /* WebViewProgressDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WebViewProgressDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 5035D5731AC540BE00E257B4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 5035D5741AC540BE00E257B4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 5035D5761AC540BE00E257B4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 5035D5771AC540BE00E257B4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 5035D5791AC540BE00E257B4 /* FirstViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; }; 39 | 5035D57A1AC540BE00E257B4 /* FirstViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; }; 40 | 5035D57C1AC540BE00E257B4 /* SecondViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 41 | 5035D57D1AC540BE00E257B4 /* SecondViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 42 | 5035D5801AC540BE00E257B4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 43 | 5035D5821AC540BE00E257B4 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 44 | 5035D5851AC540BE00E257B4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 45 | 5035D58B1AC540BE00E257B4 /* WebViewProgressDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WebViewProgressDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 5035D5901AC540BE00E257B4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 5035D5911AC540BE00E257B4 /* WebViewProgressDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebViewProgressDemoTests.m; sourceTree = ""; }; 48 | 5035D59C1AC5426A00E257B4 /* YHWebViewProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHWebViewProgress.h; sourceTree = ""; }; 49 | 5035D59D1AC5426A00E257B4 /* YHWebViewProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YHWebViewProgress.m; sourceTree = ""; }; 50 | 5035D59E1AC5426A00E257B4 /* YHWebViewProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHWebViewProgressView.h; sourceTree = ""; }; 51 | 5035D59F1AC5426A00E257B4 /* YHWebViewProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YHWebViewProgressView.m; sourceTree = ""; }; 52 | 5035D5A01AC5426A00E257B4 /* YHWebViewProgressViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHWebViewProgressViewProtocol.h; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | 5035D56C1AC540BE00E257B4 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | 5035D5881AC540BE00E257B4 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 5035D5661AC540BE00E257B4 = { 74 | isa = PBXGroup; 75 | children = ( 76 | 5035D5711AC540BE00E257B4 /* WebViewProgressDemo */, 77 | 5035D58E1AC540BE00E257B4 /* WebViewProgressDemoTests */, 78 | 5035D5701AC540BE00E257B4 /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | 5035D5701AC540BE00E257B4 /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 5035D56F1AC540BE00E257B4 /* WebViewProgressDemo.app */, 86 | 5035D58B1AC540BE00E257B4 /* WebViewProgressDemoTests.xctest */, 87 | ); 88 | name = Products; 89 | sourceTree = ""; 90 | }; 91 | 5035D5711AC540BE00E257B4 /* WebViewProgressDemo */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 5035D59B1AC5426A00E257B4 /* WebProgressView */, 95 | 5035D5761AC540BE00E257B4 /* AppDelegate.h */, 96 | 5035D5771AC540BE00E257B4 /* AppDelegate.m */, 97 | 5035D5791AC540BE00E257B4 /* FirstViewController.h */, 98 | 5035D57A1AC540BE00E257B4 /* FirstViewController.m */, 99 | 5035D57C1AC540BE00E257B4 /* SecondViewController.h */, 100 | 5035D57D1AC540BE00E257B4 /* SecondViewController.m */, 101 | 5035D57F1AC540BE00E257B4 /* Main.storyboard */, 102 | 5035D5821AC540BE00E257B4 /* Images.xcassets */, 103 | 5035D5841AC540BE00E257B4 /* LaunchScreen.xib */, 104 | 5035D5721AC540BE00E257B4 /* Supporting Files */, 105 | ); 106 | path = WebViewProgressDemo; 107 | sourceTree = ""; 108 | }; 109 | 5035D5721AC540BE00E257B4 /* Supporting Files */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 5035D5731AC540BE00E257B4 /* Info.plist */, 113 | 5035D5741AC540BE00E257B4 /* main.m */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 5035D58E1AC540BE00E257B4 /* WebViewProgressDemoTests */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 5035D5911AC540BE00E257B4 /* WebViewProgressDemoTests.m */, 122 | 5035D58F1AC540BE00E257B4 /* Supporting Files */, 123 | ); 124 | path = WebViewProgressDemoTests; 125 | sourceTree = ""; 126 | }; 127 | 5035D58F1AC540BE00E257B4 /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 5035D5901AC540BE00E257B4 /* Info.plist */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | 5035D59B1AC5426A00E257B4 /* WebProgressView */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 5035D59C1AC5426A00E257B4 /* YHWebViewProgress.h */, 139 | 5035D59D1AC5426A00E257B4 /* YHWebViewProgress.m */, 140 | 5035D59E1AC5426A00E257B4 /* YHWebViewProgressView.h */, 141 | 5035D59F1AC5426A00E257B4 /* YHWebViewProgressView.m */, 142 | 5035D5A01AC5426A00E257B4 /* YHWebViewProgressViewProtocol.h */, 143 | ); 144 | path = WebProgressView; 145 | sourceTree = ""; 146 | }; 147 | /* End PBXGroup section */ 148 | 149 | /* Begin PBXNativeTarget section */ 150 | 5035D56E1AC540BE00E257B4 /* WebViewProgressDemo */ = { 151 | isa = PBXNativeTarget; 152 | buildConfigurationList = 5035D5951AC540BE00E257B4 /* Build configuration list for PBXNativeTarget "WebViewProgressDemo" */; 153 | buildPhases = ( 154 | 5035D56B1AC540BE00E257B4 /* Sources */, 155 | 5035D56C1AC540BE00E257B4 /* Frameworks */, 156 | 5035D56D1AC540BE00E257B4 /* Resources */, 157 | ); 158 | buildRules = ( 159 | ); 160 | dependencies = ( 161 | ); 162 | name = WebViewProgressDemo; 163 | productName = WebViewProgressDemo; 164 | productReference = 5035D56F1AC540BE00E257B4 /* WebViewProgressDemo.app */; 165 | productType = "com.apple.product-type.application"; 166 | }; 167 | 5035D58A1AC540BE00E257B4 /* WebViewProgressDemoTests */ = { 168 | isa = PBXNativeTarget; 169 | buildConfigurationList = 5035D5981AC540BE00E257B4 /* Build configuration list for PBXNativeTarget "WebViewProgressDemoTests" */; 170 | buildPhases = ( 171 | 5035D5871AC540BE00E257B4 /* Sources */, 172 | 5035D5881AC540BE00E257B4 /* Frameworks */, 173 | 5035D5891AC540BE00E257B4 /* Resources */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | 5035D58D1AC540BE00E257B4 /* PBXTargetDependency */, 179 | ); 180 | name = WebViewProgressDemoTests; 181 | productName = WebViewProgressDemoTests; 182 | productReference = 5035D58B1AC540BE00E257B4 /* WebViewProgressDemoTests.xctest */; 183 | productType = "com.apple.product-type.bundle.unit-test"; 184 | }; 185 | /* End PBXNativeTarget section */ 186 | 187 | /* Begin PBXProject section */ 188 | 5035D5671AC540BE00E257B4 /* Project object */ = { 189 | isa = PBXProject; 190 | attributes = { 191 | LastUpgradeCheck = 0620; 192 | ORGANIZATIONNAME = gaoqiang; 193 | TargetAttributes = { 194 | 5035D56E1AC540BE00E257B4 = { 195 | CreatedOnToolsVersion = 6.2; 196 | }; 197 | 5035D58A1AC540BE00E257B4 = { 198 | CreatedOnToolsVersion = 6.2; 199 | TestTargetID = 5035D56E1AC540BE00E257B4; 200 | }; 201 | }; 202 | }; 203 | buildConfigurationList = 5035D56A1AC540BE00E257B4 /* Build configuration list for PBXProject "WebViewProgressDemo" */; 204 | compatibilityVersion = "Xcode 3.2"; 205 | developmentRegion = English; 206 | hasScannedForEncodings = 0; 207 | knownRegions = ( 208 | English, 209 | en, 210 | Base, 211 | ); 212 | mainGroup = 5035D5661AC540BE00E257B4; 213 | productRefGroup = 5035D5701AC540BE00E257B4 /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | 5035D56E1AC540BE00E257B4 /* WebViewProgressDemo */, 218 | 5035D58A1AC540BE00E257B4 /* WebViewProgressDemoTests */, 219 | ); 220 | }; 221 | /* End PBXProject section */ 222 | 223 | /* Begin PBXResourcesBuildPhase section */ 224 | 5035D56D1AC540BE00E257B4 /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | 5035D5811AC540BE00E257B4 /* Main.storyboard in Resources */, 229 | 5035D5861AC540BE00E257B4 /* LaunchScreen.xib in Resources */, 230 | 5035D5831AC540BE00E257B4 /* Images.xcassets in Resources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | 5035D5891AC540BE00E257B4 /* Resources */ = { 235 | isa = PBXResourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXSourcesBuildPhase section */ 244 | 5035D56B1AC540BE00E257B4 /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 5035D5A21AC5426A00E257B4 /* YHWebViewProgressView.m in Sources */, 249 | 5035D57E1AC540BE00E257B4 /* SecondViewController.m in Sources */, 250 | 5035D5A11AC5426A00E257B4 /* YHWebViewProgress.m in Sources */, 251 | 5035D5781AC540BE00E257B4 /* AppDelegate.m in Sources */, 252 | 5035D57B1AC540BE00E257B4 /* FirstViewController.m in Sources */, 253 | 5035D5751AC540BE00E257B4 /* main.m in Sources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | 5035D5871AC540BE00E257B4 /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 5035D5921AC540BE00E257B4 /* WebViewProgressDemoTests.m in Sources */, 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | }; 265 | /* End PBXSourcesBuildPhase section */ 266 | 267 | /* Begin PBXTargetDependency section */ 268 | 5035D58D1AC540BE00E257B4 /* PBXTargetDependency */ = { 269 | isa = PBXTargetDependency; 270 | target = 5035D56E1AC540BE00E257B4 /* WebViewProgressDemo */; 271 | targetProxy = 5035D58C1AC540BE00E257B4 /* PBXContainerItemProxy */; 272 | }; 273 | /* End PBXTargetDependency section */ 274 | 275 | /* Begin PBXVariantGroup section */ 276 | 5035D57F1AC540BE00E257B4 /* Main.storyboard */ = { 277 | isa = PBXVariantGroup; 278 | children = ( 279 | 5035D5801AC540BE00E257B4 /* Base */, 280 | ); 281 | name = Main.storyboard; 282 | sourceTree = ""; 283 | }; 284 | 5035D5841AC540BE00E257B4 /* LaunchScreen.xib */ = { 285 | isa = PBXVariantGroup; 286 | children = ( 287 | 5035D5851AC540BE00E257B4 /* Base */, 288 | ); 289 | name = LaunchScreen.xib; 290 | sourceTree = ""; 291 | }; 292 | /* End PBXVariantGroup section */ 293 | 294 | /* Begin XCBuildConfiguration section */ 295 | 5035D5931AC540BE00E257B4 /* Debug */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ALWAYS_SEARCH_USER_PATHS = NO; 299 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 300 | CLANG_CXX_LIBRARY = "libc++"; 301 | CLANG_ENABLE_MODULES = YES; 302 | CLANG_ENABLE_OBJC_ARC = YES; 303 | CLANG_WARN_BOOL_CONVERSION = YES; 304 | CLANG_WARN_CONSTANT_CONVERSION = YES; 305 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 306 | CLANG_WARN_EMPTY_BODY = YES; 307 | CLANG_WARN_ENUM_CONVERSION = YES; 308 | CLANG_WARN_INT_CONVERSION = YES; 309 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 310 | CLANG_WARN_UNREACHABLE_CODE = YES; 311 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 312 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 313 | COPY_PHASE_STRIP = NO; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_DYNAMIC_NO_PIC = NO; 317 | GCC_OPTIMIZATION_LEVEL = 0; 318 | GCC_PREPROCESSOR_DEFINITIONS = ( 319 | "DEBUG=1", 320 | "$(inherited)", 321 | ); 322 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 323 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 324 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 325 | GCC_WARN_UNDECLARED_SELECTOR = YES; 326 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 327 | GCC_WARN_UNUSED_FUNCTION = YES; 328 | GCC_WARN_UNUSED_VARIABLE = YES; 329 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 330 | MTL_ENABLE_DEBUG_INFO = YES; 331 | ONLY_ACTIVE_ARCH = YES; 332 | SDKROOT = iphoneos; 333 | }; 334 | name = Debug; 335 | }; 336 | 5035D5941AC540BE00E257B4 /* Release */ = { 337 | isa = XCBuildConfiguration; 338 | buildSettings = { 339 | ALWAYS_SEARCH_USER_PATHS = NO; 340 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 341 | CLANG_CXX_LIBRARY = "libc++"; 342 | CLANG_ENABLE_MODULES = YES; 343 | CLANG_ENABLE_OBJC_ARC = YES; 344 | CLANG_WARN_BOOL_CONVERSION = YES; 345 | CLANG_WARN_CONSTANT_CONVERSION = YES; 346 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 347 | CLANG_WARN_EMPTY_BODY = YES; 348 | CLANG_WARN_ENUM_CONVERSION = YES; 349 | CLANG_WARN_INT_CONVERSION = YES; 350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 351 | CLANG_WARN_UNREACHABLE_CODE = YES; 352 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 353 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 354 | COPY_PHASE_STRIP = NO; 355 | ENABLE_NS_ASSERTIONS = NO; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 365 | MTL_ENABLE_DEBUG_INFO = NO; 366 | SDKROOT = iphoneos; 367 | VALIDATE_PRODUCT = YES; 368 | }; 369 | name = Release; 370 | }; 371 | 5035D5961AC540BE00E257B4 /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 375 | INFOPLIST_FILE = WebViewProgressDemo/Info.plist; 376 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 377 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 378 | PRODUCT_NAME = "$(TARGET_NAME)"; 379 | }; 380 | name = Debug; 381 | }; 382 | 5035D5971AC540BE00E257B4 /* Release */ = { 383 | isa = XCBuildConfiguration; 384 | buildSettings = { 385 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 386 | INFOPLIST_FILE = WebViewProgressDemo/Info.plist; 387 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 388 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 389 | PRODUCT_NAME = "$(TARGET_NAME)"; 390 | }; 391 | name = Release; 392 | }; 393 | 5035D5991AC540BE00E257B4 /* Debug */ = { 394 | isa = XCBuildConfiguration; 395 | buildSettings = { 396 | BUNDLE_LOADER = "$(TEST_HOST)"; 397 | FRAMEWORK_SEARCH_PATHS = ( 398 | "$(SDKROOT)/Developer/Library/Frameworks", 399 | "$(inherited)", 400 | ); 401 | GCC_PREPROCESSOR_DEFINITIONS = ( 402 | "DEBUG=1", 403 | "$(inherited)", 404 | ); 405 | INFOPLIST_FILE = WebViewProgressDemoTests/Info.plist; 406 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 407 | PRODUCT_NAME = "$(TARGET_NAME)"; 408 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WebViewProgressDemo.app/WebViewProgressDemo"; 409 | }; 410 | name = Debug; 411 | }; 412 | 5035D59A1AC540BE00E257B4 /* Release */ = { 413 | isa = XCBuildConfiguration; 414 | buildSettings = { 415 | BUNDLE_LOADER = "$(TEST_HOST)"; 416 | FRAMEWORK_SEARCH_PATHS = ( 417 | "$(SDKROOT)/Developer/Library/Frameworks", 418 | "$(inherited)", 419 | ); 420 | INFOPLIST_FILE = WebViewProgressDemoTests/Info.plist; 421 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 422 | PRODUCT_NAME = "$(TARGET_NAME)"; 423 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WebViewProgressDemo.app/WebViewProgressDemo"; 424 | }; 425 | name = Release; 426 | }; 427 | /* End XCBuildConfiguration section */ 428 | 429 | /* Begin XCConfigurationList section */ 430 | 5035D56A1AC540BE00E257B4 /* Build configuration list for PBXProject "WebViewProgressDemo" */ = { 431 | isa = XCConfigurationList; 432 | buildConfigurations = ( 433 | 5035D5931AC540BE00E257B4 /* Debug */, 434 | 5035D5941AC540BE00E257B4 /* Release */, 435 | ); 436 | defaultConfigurationIsVisible = 0; 437 | defaultConfigurationName = Release; 438 | }; 439 | 5035D5951AC540BE00E257B4 /* Build configuration list for PBXNativeTarget "WebViewProgressDemo" */ = { 440 | isa = XCConfigurationList; 441 | buildConfigurations = ( 442 | 5035D5961AC540BE00E257B4 /* Debug */, 443 | 5035D5971AC540BE00E257B4 /* Release */, 444 | ); 445 | defaultConfigurationIsVisible = 0; 446 | defaultConfigurationName = Release; 447 | }; 448 | 5035D5981AC540BE00E257B4 /* Build configuration list for PBXNativeTarget "WebViewProgressDemoTests" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | 5035D5991AC540BE00E257B4 /* Debug */, 452 | 5035D59A1AC540BE00E257B4 /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | /* End XCConfigurationList section */ 458 | }; 459 | rootObject = 5035D5671AC540BE00E257B4 /* Project object */; 460 | } 461 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/FirstViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import "FirstViewController.h" 10 | #import "YHWebViewProgress.h" 11 | #import "YHWebViewProgressView.h" 12 | 13 | @interface FirstViewController () 14 | 15 | 16 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 17 | @property (strong, nonatomic) YHWebViewProgress *progressProxy; 18 | @end 19 | 20 | @implementation FirstViewController 21 | 22 | - (void)viewDidLoad 23 | { 24 | [super viewDidLoad]; 25 | 26 | // 创建进度条代理,用于处理进度控制 27 | _progressProxy = [[YHWebViewProgress alloc] init]; 28 | 29 | // 创建进度条 30 | YHWebViewProgressView *progressView = [[YHWebViewProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), CGRectGetWidth(self.view.bounds), 4)]; 31 | progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin; 32 | 33 | // 设置进度条 34 | self.progressProxy.progressView = progressView; 35 | // 将UIWebView代理指向YHWebViewProgress 36 | self.webView.delegate = self.progressProxy; 37 | // 设置webview代理转发到self(可选) 38 | self.progressProxy.webViewProxy = self; 39 | 40 | // 添加到视图 41 | [self.view addSubview:progressView]; 42 | } 43 | 44 | - (void)viewDidAppear:(BOOL)animated 45 | { 46 | [super viewDidAppear:animated]; 47 | 48 | [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://m.taobao.com"]]]; 49 | } 50 | 51 | #pragma mark - UIWebViewDelegate 52 | - (void)webViewDidFinishLoad:(UIWebView *)webView 53 | { 54 | self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealedace/WebViewProgressView/3df6fbd00faa7a167581449e96dbc3a77931961d/WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealedace/WebViewProgressView/3df6fbd00faa7a167581449e96dbc3a77931961d/WebViewProgressDemo/WebViewProgressDemo/Images.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | Tangram.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UIStatusBarTintParameters 39 | 40 | UINavigationBar 41 | 42 | Style 43 | UIBarStyleDefault 44 | Translucent 45 | 46 | 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | #import "YHWebViewProgressView.h" 11 | 12 | @import WebKit; 13 | 14 | @interface SecondViewController () 15 | 16 | @property (strong, nonatomic) WKWebView *webView; 17 | 18 | @end 19 | 20 | @implementation SecondViewController 21 | 22 | - (WKWebView *)webView 23 | { 24 | if (!_webView) { 25 | _webView = [[WKWebView alloc] initWithFrame:self.view.bounds]; 26 | _webView.navigationDelegate = self; 27 | } 28 | return _webView; 29 | } 30 | 31 | - (void)viewDidLoad 32 | { 33 | [super viewDidLoad]; 34 | 35 | [self.view addSubview:self.webView]; 36 | 37 | self.webView.translatesAutoresizingMaskIntoConstraints = NO; 38 | [self.webView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES; 39 | [self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES; 40 | [self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES; 41 | [self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; 42 | 43 | // 创建进度条 44 | YHWebViewProgressView *progressView = [[YHWebViewProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), CGRectGetWidth(self.view.bounds), 4)]; 45 | progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin; 46 | 47 | [progressView useWkWebView:self.webView]; 48 | 49 | // 添加到视图 50 | [self.view addSubview:progressView]; 51 | 52 | [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil]; 53 | } 54 | 55 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 56 | { 57 | self.navigationItem.title = change[@"new"]; 58 | } 59 | 60 | - (void)viewDidAppear:(BOOL)animated 61 | { 62 | [super viewDidAppear:animated]; 63 | 64 | [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://m.taobao.com"]]]; 65 | } 66 | 67 | #pragma mark - WKNavigationDelegate 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/WebProgressView/YHWebViewProgress.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgress.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "YHWebViewProgressViewProtocol.h" 11 | 12 | @interface YHWebViewProgress : NSObject 13 | 14 | 15 | @property (readonly, nonatomic) float progress; 16 | /** 17 | * 进度条 18 | */ 19 | @property (strong, nonatomic) UIView *progressView; 20 | /** 21 | * 转发WebViewDelegate 22 | */ 23 | @property (weak, nonatomic) id webViewProxy; 24 | 25 | 26 | // 外部使用时,不要调用该方法 27 | - (BOOL)checkIfRPCURL:(NSURLRequest *)request; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/WebProgressView/YHWebViewProgress.m: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgress.m 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import "YHWebViewProgress.h" 10 | 11 | NSString *completeRPCURLPath = @"/yhwebviewprogressproxy/complete"; 12 | 13 | static const float YHWebViewProgressInitialValue = 0.7f; 14 | static const float YHWebViewProgressInteractiveValue = 0.9f; 15 | static const float YHWebViewProgressFinalProgressValue = 0.9f; 16 | 17 | @interface YHWebViewProgress () 18 | @property (nonatomic) NSUInteger loadingCount; 19 | @property (nonatomic) NSUInteger maxLoadCount; 20 | @property (strong, nonatomic) NSURL *currentURL; 21 | @property (nonatomic) BOOL interactive; 22 | 23 | @property (nonatomic) float progress; 24 | 25 | /** 26 | * 重置 27 | */ 28 | - (void)reset; 29 | 30 | @end 31 | 32 | @implementation YHWebViewProgress 33 | 34 | - (instancetype)init 35 | { 36 | self = [super init]; 37 | if (self) { 38 | _maxLoadCount = _loadingCount = 0; 39 | _interactive = NO; 40 | } 41 | 42 | return self; 43 | } 44 | 45 | - (void)dealloc 46 | { 47 | 48 | } 49 | 50 | - (void)startProgress 51 | { 52 | if (self.progress < YHWebViewProgressInitialValue) { 53 | [self setProgress:YHWebViewProgressInitialValue]; 54 | } 55 | } 56 | 57 | - (void)incrementProgress 58 | { 59 | float progress = self.progress; 60 | float maxProgress = self.interactive?YHWebViewProgressFinalProgressValue:YHWebViewProgressInteractiveValue; 61 | float remainPercent = (float)self.loadingCount/self.maxLoadCount; 62 | float increment = (maxProgress-progress) * remainPercent; 63 | progress += increment; 64 | progress = fminf(progress, maxProgress); 65 | [self setProgress:progress]; 66 | } 67 | 68 | - (void)completeProgress 69 | { 70 | [self setProgress:1.f]; 71 | } 72 | 73 | - (void)setProgress:(float)progress 74 | { 75 | if (progress > _progress || progress == 0) { 76 | _progress = progress; 77 | 78 | if (self.progressView) { 79 | [self.progressView setProgress:progress animated:YES]; 80 | } 81 | } 82 | } 83 | 84 | - (void)reset 85 | { 86 | self.maxLoadCount = self.loadingCount = 0; 87 | self.interactive = NO; 88 | [self setProgress:0.f]; 89 | } 90 | 91 | - (BOOL)checkIfRPCURL:(NSURLRequest *)request 92 | { 93 | if ([request.URL.path isEqualToString:completeRPCURLPath]) { 94 | [self completeProgress]; 95 | return YES; 96 | } 97 | 98 | return NO; 99 | } 100 | 101 | #pragma mark - UIWebViewDelegate 102 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 103 | { 104 | BOOL ret = YES; 105 | 106 | if (self.webViewProxy) { 107 | if ([self checkIfRPCURL:request]) { 108 | return NO; 109 | } 110 | 111 | if ([self.webViewProxy respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { 112 | ret = [self.webViewProxy webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; 113 | } 114 | } 115 | 116 | BOOL isFragmentJump = NO; 117 | if (request.URL.fragment) { 118 | NSString *nonFragmentURL = [request.URL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:request.URL.fragment] withString:@""]; 119 | isFragmentJump = [nonFragmentURL isEqualToString:webView.request.URL.absoluteString]; 120 | } 121 | 122 | BOOL isTopLevelNavigation = [request.mainDocumentURL isEqual:request.URL]; 123 | 124 | BOOL isHTTP = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"]; 125 | if (ret && !isFragmentJump && isHTTP && isTopLevelNavigation) { 126 | self.currentURL = request.URL; 127 | [self reset]; 128 | } 129 | 130 | return ret; 131 | } 132 | 133 | - (void)webViewDidStartLoad:(UIWebView *)webView 134 | { 135 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webViewDidStartLoad:)]) { 136 | [self.webViewProxy webViewDidStartLoad:webView]; 137 | } 138 | 139 | self.loadingCount++; 140 | 141 | self.maxLoadCount = fmax(self.loadingCount, self.loadingCount); 142 | 143 | [self startProgress]; 144 | } 145 | 146 | - (void)webViewDidFinishLoad:(UIWebView *)webView 147 | { 148 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webViewDidFinishLoad:)]) { 149 | [self.webViewProxy webViewDidFinishLoad:webView]; 150 | } 151 | 152 | self.loadingCount--; 153 | [self incrementProgress]; 154 | 155 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 156 | 157 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 158 | if (interactive) { 159 | self.interactive = interactive; 160 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", 161 | webView.request.mainDocumentURL.scheme, 162 | webView.request.mainDocumentURL.host, 163 | completeRPCURLPath]; 164 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 165 | } 166 | 167 | BOOL isNotRedirect = self.currentURL && [self.currentURL isEqual:webView.request.mainDocumentURL]; 168 | BOOL complete = [readyState isEqualToString:@"complete"]; 169 | if (complete && isNotRedirect) { 170 | [self completeProgress]; 171 | } 172 | } 173 | 174 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 175 | { 176 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 177 | [self.webViewProxy webView:webView didFailLoadWithError:error]; 178 | } 179 | 180 | _loadingCount--; 181 | [self incrementProgress]; 182 | 183 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 184 | 185 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 186 | if (interactive) { 187 | self.interactive = YES; 188 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", webView.request.mainDocumentURL.scheme, webView.request.mainDocumentURL.host, completeRPCURLPath]; 189 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 190 | } 191 | 192 | BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL]; 193 | BOOL complete = [readyState isEqualToString:@"complete"]; 194 | if ((complete && isNotRedirect) || error) { 195 | [self completeProgress]; 196 | } 197 | } 198 | 199 | #pragma mark - Method Forwarding 200 | - (BOOL)respondsToSelector:(SEL)aSelector 201 | { 202 | if ([super respondsToSelector:aSelector]) { 203 | return YES; 204 | } 205 | 206 | if ([self.webViewProxy respondsToSelector:aSelector]) { 207 | return YES; 208 | } 209 | 210 | return NO; 211 | } 212 | 213 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 214 | { 215 | NSMethodSignature *signature = [super methodSignatureForSelector:aSelector]; 216 | if (!signature) { 217 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:aSelector]) { 218 | return [(NSObject *)self.webViewProxy methodSignatureForSelector:aSelector]; 219 | } 220 | } 221 | 222 | return signature; 223 | } 224 | 225 | - (void)forwardInvocation:(NSInvocation *)anInvocation 226 | { 227 | if (self.webViewProxy && [self.webViewProxy respondsToSelector:[anInvocation selector]]) { 228 | [anInvocation invokeWithTarget:self.webViewProxy]; 229 | } 230 | } 231 | 232 | @end 233 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/WebProgressView/YHWebViewProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressView.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "YHWebViewProgressViewProtocol.h" 11 | @import WebKit; 12 | 13 | @interface YHWebViewProgressView : UIView 14 | 15 | @property (nonatomic) float progress; 16 | 17 | @property (readonly, nonatomic) UIView *progressBarView; 18 | @property (nonatomic) NSTimeInterval barAnimationDuration;// default 0.5 19 | @property (nonatomic) NSTimeInterval fadeAnimationDuration;// default 0.27 20 | /** 21 | * 进度条的颜色 22 | */ 23 | @property (copy, nonatomic) UIColor *progressBarColor; 24 | 25 | /** 26 | * 使用WKWebKit 27 | * 28 | * @param webView WKWebView对象 29 | */ 30 | - (void)useWkWebView:(WKWebView *)webView; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/WebProgressView/YHWebViewProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressView.m 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | #import "YHWebViewProgressView.h" 10 | 11 | #define kAnimationDurationMultiplier (1.8) 12 | 13 | @interface YHWebViewProgressView () 14 | @property (nonatomic) BOOL isWkWebView; 15 | @end 16 | 17 | @implementation YHWebViewProgressView 18 | 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | self = [super initWithFrame:frame]; 22 | if (self) { 23 | [self configureViews]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (void)awakeFromNib 30 | { 31 | [super awakeFromNib]; 32 | [self configureViews]; 33 | } 34 | 35 | - (void)dealloc 36 | { 37 | 38 | } 39 | 40 | - (void)configureViews 41 | { 42 | self.isWkWebView = NO; 43 | self.userInteractionEnabled = NO; 44 | self.clipsToBounds = YES; 45 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 46 | _progressBarView = [[UIView alloc] initWithFrame:self.bounds]; 47 | _progressBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 48 | UIColor *tintColor = [UIColor colorWithRed:22/255.f 49 | green:126/255.f 50 | blue:251/255.f 51 | alpha:1.f]; 52 | 53 | if ([UIApplication.sharedApplication.delegate.window respondsToSelector:@selector(setTintColor:)] 54 | && UIApplication.sharedApplication.delegate.window.tintColor) { 55 | tintColor = UIApplication.sharedApplication.delegate.window.tintColor; 56 | } 57 | 58 | _progressBarView.backgroundColor = tintColor; 59 | [self addSubview:_progressBarView]; 60 | 61 | _barAnimationDuration = 0.5f; 62 | _fadeAnimationDuration = 0.27f; 63 | 64 | [self setProgress:0.f]; 65 | } 66 | 67 | - (void)setProgressBarColor:(UIColor *)progressBarColor 68 | { 69 | _progressBarView.backgroundColor = progressBarColor; 70 | } 71 | 72 | - (UIColor *)progressBarColor 73 | { 74 | return self.progressBarView.backgroundColor; 75 | } 76 | 77 | - (void)setProgress:(float)progress 78 | { 79 | [self setProgress:progress animated:NO]; 80 | } 81 | 82 | - (void)useWkWebView:(WKWebView *)webView 83 | { 84 | if (!webView) { 85 | return; 86 | } 87 | self.isWkWebView = YES; 88 | [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; 89 | } 90 | 91 | - (void)setProgress:(float)progress animated:(BOOL)animated 92 | { 93 | BOOL isGrowing = progress > 0.f; 94 | 95 | CGFloat originX = -CGRectGetWidth(self.bounds)/2; 96 | CGPoint positionBegin = CGPointMake(originX+_progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2); 97 | CGPoint positionEnd = CGPointMake(originX+progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2); 98 | 99 | if (progress < _progress) { 100 | animated = NO; 101 | } 102 | 103 | if (!isGrowing) { 104 | if (animated) { 105 | [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f 106 | delay:0 107 | options:UIViewAnimationOptionCurveEaseInOut 108 | animations:^{ 109 | self.progressBarView.center = positionEnd; 110 | self.progressBarView.alpha = 1.f; 111 | } completion:^(BOOL finished) {}]; 112 | } else { 113 | self.progressBarView.alpha = 1.f; 114 | self.progressBarView.center = positionEnd; 115 | } 116 | } else { 117 | [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f 118 | delay:0 119 | options:UIViewAnimationOptionCurveEaseInOut 120 | animations:^{ 121 | self.progressBarView.alpha = 1.f; 122 | } completion:^(BOOL finished) {}]; 123 | 124 | if (animated) { 125 | CAAnimation *animationBounds = nil; 126 | 127 | if (progress < 1) { 128 | if (_progress > 0.01 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) { 129 | positionBegin = [self.progressBarView.layer.presentationLayer position]; 130 | self.progressBarView.layer.position = positionBegin; 131 | [self.progressBarView.layer removeAnimationForKey:@"positionAnimation"]; 132 | } 133 | 134 | CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 135 | keyFrameAnimation.duration = kAnimationDurationMultiplier*(progress-_progress)*10; 136 | keyFrameAnimation.keyTimes = @[ @0, @.3, @1 ]; 137 | keyFrameAnimation.values = @[ [NSValue valueWithCGPoint:positionBegin], 138 | [NSValue valueWithCGPoint:CGPointMake(positionBegin.x+(positionEnd.x-positionBegin.x)*0.9, positionEnd.y)], 139 | [NSValue valueWithCGPoint:positionEnd] ]; 140 | keyFrameAnimation.timingFunctions = @[ [CAMediaTimingFunction functionWithControlPoints: 0.092 : 0.000 : 0.618 : 1.000], 141 | [CAMediaTimingFunction functionWithControlPoints: 0.000 : 0.688 : 0.479 : 1.000] ]; 142 | 143 | animationBounds = keyFrameAnimation; 144 | } else { 145 | if (_progress > 0.05 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) { 146 | positionBegin = [self.progressBarView.layer.presentationLayer position]; 147 | self.progressBarView.layer.position = positionBegin; 148 | [self.progressBarView.layer removeAnimationForKey:@"positionAnimation"]; 149 | } 150 | CABasicAnimation *basicAnimationBounds = [CABasicAnimation animationWithKeyPath:@"position"]; 151 | basicAnimationBounds.fromValue = [NSValue valueWithCGPoint:positionBegin]; 152 | basicAnimationBounds.toValue = [NSValue valueWithCGPoint:positionEnd]; 153 | basicAnimationBounds.duration = self.barAnimationDuration; 154 | basicAnimationBounds.timingFunction = [CAMediaTimingFunction functionWithControlPoints: 0.486 : 0.056 : 0.778 : 0.480]; 155 | 156 | basicAnimationBounds.delegate = self; 157 | 158 | animationBounds = basicAnimationBounds; 159 | } 160 | 161 | [self.progressBarView.layer addAnimation:animationBounds forKey:@"positionAnimation"]; 162 | self.progressBarView.layer.position = positionEnd; 163 | 164 | } else { 165 | self.progressBarView.layer.position = positionEnd; 166 | } 167 | } 168 | 169 | _progress = progress; 170 | } 171 | 172 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 173 | { 174 | _progress = 0.f; 175 | CABasicAnimation *animationOpacity = [CABasicAnimation animationWithKeyPath:@"opacity"]; 176 | animationOpacity.fromValue = @1; 177 | animationOpacity.toValue = @0; 178 | animationOpacity.duration = self.fadeAnimationDuration; 179 | animationOpacity.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 180 | [self.progressBarView.layer addAnimation:animationOpacity forKey:@"opacityAnimation"]; 181 | self.progressBarView.layer.opacity = 0; 182 | } 183 | 184 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 185 | { 186 | [self setProgress:[change[@"new"] doubleValue] animated:YES]; 187 | } 188 | 189 | @end 190 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/WebProgressView/YHWebViewProgressViewProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // YHWebViewProgressViewProtocol.h 3 | // YohoExplorerDemo 4 | // 5 | // Created by gaoqiang xu on 3/25/15. 6 | // Copyright (c) 2015 gaoqiang xu. All rights reserved. 7 | // 8 | 9 | @protocol YHWebViewProgressViewProtocol 10 | @required 11 | - (void)setProgress:(float)progress animated:(BOOL)animated; 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WebViewProgressDemo 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | Tangram.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /WebViewProgressDemo/WebViewProgressDemoTests/WebViewProgressDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewProgressDemoTests.m 3 | // WebViewProgressDemoTests 4 | // 5 | // Created by gaoqiang xu on 3/27/15. 6 | // Copyright (c) 2015 gaoqiang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface WebViewProgressDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation WebViewProgressDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------