微信webView加載時(shí)候在導(dǎo)航條下回出現(xiàn)一個(gè)綠色進(jìn)度條箱蝠。
雖然進(jìn)度條是假的,但是給用戶提供了更好操作體驗(yàn)宦搬。
我們可以用幀動(dòng)畫實(shí)現(xiàn)
這里把layer加到了(0,100)這所在行位置
- (void)testFunction{
//添加layer
CAShapeLayer *animationLayer = [CAShapeLayer layer];
animationLayer.lineWidth = 3 ;
animationLayer.strokeColor = [UIColor colorWithRed:28/255. green:189/255. blue:39/255. alpha:1].CGColor;
[self.view.layer addSublayer:_animationLayer];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 100)];
[path addLineToPoint:CGPointMake(SCREEN_WIDTH, 100)];
self.animationLayer.path = path.CGPath;
CAKeyframeAnimation *animations = [CAKeyframeAnimation animation];
animations.keyPath = @"strokeEnd";
animations.duration = 25.0;
//關(guān)鍵幀數(shù)組,實(shí)現(xiàn)進(jìn)度由塊到慢
animations.values = @[@0, @0.6, @0.85, @1];
//設(shè)定關(guān)鍵幀指定對應(yīng)時(shí)間點(diǎn)
animations.keyTimes = @[@0,@(1./25),@(3./25),@1];
[self.animationLayer addAnimation:animations forKey:nil];
}
webView加載完成時(shí),可以用再覆蓋一層layer,顯示加載完成间校。
- (void)testFunction{
CAShapeLayer *animationLayer = [CAShapeLayer layer];
animationLayer.lineWidth = 3 ;
animationLayer.strokeColor = [UIColor colorWithRed:28/255. green:189/255. blue:39/255. alpha:1].CGColor;
[self.view.layer addSublayer:animationLayer];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 100)];
[path addLineToPoint:CGPointMake(SCREEN_WIDTH, 100)];
animationLayer.path = path.CGPath;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = @(0.0);
animation.toValue = @(1.0);
animationLayer.autoreverses = NO;
animation.duration = 0.3;
animation.delegate = self;
[animationLayer addAnimation:animation forKey:nil];
}