Authored by wang

滚动条效果优化 code review by 高强

... ... @@ -45,9 +45,9 @@
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_progressBarView = [[UIView alloc] initWithFrame:self.bounds];
_progressBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
UIColor *tintColor = [UIColor colorWithRed:0/255.f
green:191/255.f
blue:18/255.f
UIColor *tintColor = [UIColor colorWithRed:88/255.f
green:88/255.f
blue:88/255.f
alpha:1.f];
if ([UIApplication.sharedApplication.delegate.window respondsToSelector:@selector(setTintColor:)]
... ... @@ -59,7 +59,7 @@
[self addSubview:_progressBarView];
_barAnimationDuration = 0.5f;
_fadeAnimationDuration = 0.27f;
_fadeAnimationDuration = 0.4f;
[self setProgress:0.f];
}
... ... @@ -91,11 +91,14 @@
- (void)setProgress:(float)progress animated:(BOOL)animated
{
BOOL isGrowing = progress > 0.f;
UIImageView * maskImageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Mask"]];
self.progressBarView.maskView = maskImageView;
CGFloat originX = -CGRectGetWidth(self.bounds)/2;
CGPoint positionBegin = CGPointMake(originX+_progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2);
CGPoint positionEnd = CGPointMake(originX+progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2);
[maskImageView setFrame:CGRectMake(0, 0,progress * self.bounds.size.width, 2)];
if (progress < _progress) {
animated = NO;
}
... ... @@ -175,6 +178,97 @@
_progress = progress;
}
//- (void)setProgress:(float)progress animated:(BOOL)animated
//{
// BOOL isGrowing = progress > 0.f;
//
// CGFloat originX = -CGRectGetWidth(self.bounds)/2;
// CGPoint positionBegin = CGPointMake(originX+_progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2);
// CGPoint positionEnd = CGPointMake(originX+progress * self.bounds.size.width, CGRectGetHeight(self.progressBarView.frame)/2);
//
// if (progress < _progress) {
// animated = NO;
// }
//
// if (!isGrowing) {
// if (animated) {
// [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f
// delay:0
// options:UIViewAnimationOptionCurveEaseInOut
// animations:^{
// self.progressBarView.center = positionEnd;
// self.progressBarView.alpha = 1.f;
// } completion:^(BOOL finished) {}];
// } else {
// self.progressBarView.alpha = 1.f;
// self.progressBarView.center = positionEnd;
// }
//
// } else {
// [UIView animateWithDuration:animated?self.fadeAnimationDuration:0.f
// delay:0
// options:UIViewAnimationOptionCurveEaseInOut
// animations:^{
// self.progressBarView.alpha = 1.f;
// } completion:^(BOOL finished) {}];
//
// if (animated) {
// 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-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)],
// [NSValue valueWithCGPoint:positionEnd] ];
// keyFrameAnimation.timingFunctions = @[ [CAMediaTimingFunction functionWithControlPoints: 0.092 : 0.000 : 0.618 : 1.000],
// [CAMediaTimingFunction functionWithControlPoints: 0.000 : 0.688 : 0.479 : 1.000] ];
//
// animationBounds = keyFrameAnimation;
// } else {
// if (_progress > 0.05 && [self.progressBarView.layer animationForKey:@"positionAnimation"]) {
// positionBegin = [self.progressBarView.layer.presentationLayer position];
// self.progressBarView.layer.position = positionBegin;
// [self.progressBarView.layer removeAnimationForKey:@"positionAnimation"];
// }
// CABasicAnimation *basicAnimationBounds = [CABasicAnimation animationWithKeyPath:@"position"];
// basicAnimationBounds.fromValue = [NSValue valueWithCGPoint:positionBegin];
// basicAnimationBounds.toValue = [NSValue valueWithCGPoint:positionEnd];
// basicAnimationBounds.duration = self.barAnimationDuration;
// basicAnimationBounds.timingFunction = [CAMediaTimingFunction functionWithControlPoints: 0.486 : 0.056 : 0.778 : 0.480];
//
// basicAnimationBounds.delegate = self;
//
// animationBounds = basicAnimationBounds;
// }
//
// [self.progressBarView.layer addAnimation:animationBounds forKey:@"positionAnimation"];
// self.progressBarView.layer.position = positionEnd;
//
// } else {
// self.progressBarView.layer.position = positionEnd;
// }
// }
//
// _progress = progress;
//}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (!flag) {
... ...
... ... @@ -6,27 +6,54 @@
// Copyright (c) 2015 gaoqiang xu. All rights reserved.
//
static float kprogressViewHeight = 2.0f;
static float kprogressViewRadius = 2.0f;
#import "YHExplorerViewController.h"
#import "YHWebViewProgress.h"
#import "YHWebViewProgressView.h"
@interface YHExplorerViewController ()
@property (strong, nonatomic) YHWebViewProgress *progressBar;
@property (strong, nonatomic) YHWebViewProgressView *progressView;
@property (strong, nonatomic) NSMutableArray *nativeAbilities;
@property (nonatomic) BOOL isAppeared;
@property (strong, nonatomic) NSMutableArray *linkParsers;
@property (strong, nonatomic) NSValue *pointerValue;
@property (weak, nonatomic) UINavigationBar *currentNaviBar;
@end
@implementation YHExplorerViewController
- (BOOL)navigationControllerShouldPop:(UINavigationController *)navigationController {
NSLog(@"%@ 点击\n%s", [self class], __func__);
return YES;
}
- (BOOL)navigationControllerShouldStartInteractivePopGestureRecognizer:(UINavigationController *)navigationController {
NSLog(@"%@ 手势\n%s", [self class], __func__);
return YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
[self.progressView removeFromSuperview];
}
- (void)dealloc
{
[self.webView stopLoading];
self.webView.delegate = nil;
[self.webView removeFromSuperview];
self.webView = nil;
if ([[NSURLCache sharedURLCache] isKindOfClass:[YHURLCache class]]) {
... ... @@ -61,7 +88,7 @@
[self registerLinkParser:parser];
if (self.progressBar && !self.progressBar.progressView.superview) {
[self.view addSubview:self.progressBar.progressView];
[self.currentNaviBar addSubview:self.progressBar.progressView];
}
}
... ... @@ -76,9 +103,9 @@
self.isAppeared = YES;
if (self.progressBar) {
if (!self.progressBar.progressView.superview) {
[self.view addSubview:self.progressBar.progressView];
[self.currentNaviBar addSubview:self.progressBar.progressView];
} else {
[self.view bringSubviewToFront:self.progressBar.progressView];
[self.currentNaviBar bringSubviewToFront:self.progressBar.progressView];
}
}
}
... ... @@ -117,14 +144,28 @@
_progressBarEnabled = progressBarEnabled;
if (progressBarEnabled) {
YHWebViewProgressView *view = [[YHWebViewProgressView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 4.f)];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
self.progressView = [[YHWebViewProgressView alloc]init];
UIViewController *currentVC = [self getCurrentVC];
self.progressView.layer.cornerRadius = kprogressViewRadius;
if ([currentVC isKindOfClass:[UINavigationController class]]) {
UINavigationController *currentNavigationVC = (UINavigationController *)currentVC;
self.currentNaviBar = currentNavigationVC.navigationBar;
[self.progressView setFrame:CGRectMake(0, CGRectGetHeight(_currentNaviBar.frame)-kprogressViewHeight-1, CGRectGetWidth(self.view.frame), kprogressViewHeight)];
self.progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
if (self.isAppeared) {
[_currentNaviBar addSubview:self.progressView];
}
}else{
[self.progressView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), kprogressViewHeight)];
self.progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin;
if (self.isAppeared) {
[self.view addSubview:view];
[self.view addSubview:self.progressView];
}
}
_progressBar = [[YHWebViewProgress alloc] init];
_progressBar.progressView = view;
_progressBar.progressView = self.progressView;
} else {
if (self.progressBar) {
... ... @@ -406,6 +447,36 @@
}
}
#pragma mark - get current ViewController
- (UIViewController *)getCurrentVC
{
UIViewController *result = nil;
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView *frontView = [[window subviews] objectAtIndex:0];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
result = nextResponder;
else
result = window.rootViewController;
return result;
}
@end
... ...
... ... @@ -73,7 +73,7 @@
} else if ([title isEqualToString:@"链接跳转"]) {
wv.url = @"http://sealedace.com/content/images/test/h5_test.html";
} else {
wv.url = @"http://yohomars.test.yoho.cn/message/index?uid=8655817&session_code=008413c9940c1e6c361531b12c3f506d";
wv.url = @"http://guang.m.yohobuy.com";
}
[self.navigationController pushViewController:wv animated:YES];
... ...