Authored by gaoqiang xu

优化进度条

... ... @@ -10,9 +10,9 @@
NSString *completeRPCURLPath = @"/yhwebviewprogressproxy/complete";
static const float YHWebViewProgressInitialValue = 0.7f;
static const float YHWebViewProgressInteractiveValue = 0.9f;
static const float YHWebViewProgressFinalProgressValue = 0.9f;
static const float YHWebViewProgressInitialValue = 0.94f;
static const float YHWebViewProgressInteractiveValue = 0.95f;
static const float YHWebViewProgressFinalProgressValue = 0.96f;
@interface YHWebViewProgress ()
@property (nonatomic) NSUInteger loadingCount;
... ... @@ -53,10 +53,15 @@ static const float YHWebViewProgressFinalProgressValue = 0.9f;
{
float progress = self.progress;
float maxProgress = self.interactive?YHWebViewProgressFinalProgressValue:YHWebViewProgressInteractiveValue;
if (self.loadingCount == 0) {
progress = maxProgress;
} else {
float remainPercent = (float)self.loadingCount/self.maxLoadCount;
float increment = (maxProgress-progress) * remainPercent;
progress += increment;
progress = fminf(progress, maxProgress);
}
[self setProgress:progress];
}
... ... @@ -133,7 +138,7 @@ static const float YHWebViewProgressFinalProgressValue = 0.9f;
self.loadingCount++;
self.maxLoadCount = fmax(self.loadingCount, self.loadingCount);
self.maxLoadCount = self.loadingCount;
[self startProgress];
}
... ... @@ -172,8 +177,10 @@ static const float YHWebViewProgressFinalProgressValue = 0.9f;
[self.webViewProxy webView:webView didFailLoadWithError:error];
}
_loadingCount--;
if (error && error.code != NSURLErrorCancelled) {
self.loadingCount--;
[self incrementProgress];
}
NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
... ... @@ -186,7 +193,7 @@ static const float YHWebViewProgressFinalProgressValue = 0.9f;
BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
BOOL complete = [readyState isEqualToString:@"complete"];
if ((complete && isNotRedirect) || error) {
if ((complete && isNotRedirect) || (error && error.code != NSURLErrorCancelled)) {
[self completeProgress];
}
}
... ...
... ... @@ -113,6 +113,7 @@
self.progressBarView.alpha = 1.f;
self.progressBarView.center = positionEnd;
}
} else {
[UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f
delay:0
... ... @@ -125,14 +126,19 @@
CAAnimation *animationBounds = nil;
if (progress < 1) {
CGFloat lastProgress = _progress;
if (_progress > 0.01 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) {
positionBegin = [self.progressBarView.layer.presentationLayer position];
self.progressBarView.layer.position = positionBegin;
CAKeyframeAnimation *animation = (CAKeyframeAnimation*)[self.progressBarView.layer animationForKey:@"positionAnimation"];
lastProgress = positionBegin.x / ([[animation.values lastObject] CGPointValue].x - [[animation.values firstObject] CGPointValue].x);
[self.progressBarView.layer removeAnimationForKey:@"positionAnimation"];
}
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyFrameAnimation.duration = kAnimationDurationMultiplier*(progress-_progress)*10;
keyFrameAnimation.duration = kAnimationDurationMultiplier*(progress-lastProgress)*10;
keyFrameAnimation.keyTimes = @[ @0, @.3, @1 ];
keyFrameAnimation.values = @[ [NSValue valueWithCGPoint:positionBegin],
[NSValue valueWithCGPoint:CGPointMake(positionBegin.x+(positionEnd.x-positionBegin.x)*0.9, positionEnd.y)],
... ... @@ -171,6 +177,9 @@
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (!flag) {
return;
}
_progress = 0.f;
CABasicAnimation *animationOpacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
animationOpacity.fromValue = @1;
... ...
... ... @@ -38,7 +38,8 @@ NSString * const YHLinkParseResult_OriginalUrlKey = @"YHLinkParseResult_Original
if (range.location != NSNotFound) {
contentString = [contentString substringFromIndex:range.location+range.length];
freshUrl = [string substringToIndex:range.location];
if ([[freshUrl substringWithRange:NSMakeRange(freshUrl.length-1, 1)] isEqualToString:@"?"]) {
if (freshUrl.length > 0
&& [[freshUrl substringWithRange:NSMakeRange(freshUrl.length-1, 1)] isEqualToString:@"?"]) {
freshUrl = [freshUrl substringToIndex:freshUrl.length-1];
}
} else {
... ...
... ... @@ -2,4 +2,30 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "../YHExplorer/WebProgressView/YHWebViewProgressView.m"
timestampString = "460284588.269866"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "91"
endingLineNumber = "91"
landmarkName = "-setProgress:animated:"
landmarkType = "5">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "p progress">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
... ...
... ... @@ -73,7 +73,7 @@
} else if ([title isEqualToString:@"链接跳转"]) {
wv.url = @"http://sealedace.com/content/images/test/h5_test.html";
} else {
wv.url = @"http://yohood.test.yoho.cn/brand/index/client/1";
wv.url = @"http://m.taobao.com";
}
[self.navigationController pushViewController:wv animated:YES];
... ...