仿微信WebView加载动画

微信webView加载时候在导航条下回出现一个绿色进度条。

虽然进度条是假的,但是给用户提供了更好操作体验。

2017021068848li23.gif

我们可以用帧动画实现

这里把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;
    
    //关键帧数组,实现进度由块到慢
    animations.values = @[@0, @0.6, @0.85, @1];
    //设定关键帧指定对应时间点
    animations.keyTimes = @[@0,@(1./25),@(3./25),@1];
    [self.animationLayer addAnimation:animations forKey:nil];   
}

webView加载完成时,可以用再覆盖一层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];
}

Demo地址

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,885评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,262评论 4 61
  • 两个人在玩积木 a:我要在沙发这里按个摄像头 b:不会吧,我不同意 a:我就要 b:我不同意 a:那我就把它破坏了...
    娜可露露斯基阅读 89评论 0 0
  • 固定参数 无参 有参 默认参数 可变参数 关键字参数 转载 http://www.cnblogs.com/tqsu...
    linheimx阅读 249评论 0 1
  • 你在慈云寺吃肯德基 到了中关村吃肯德基他的味道是一样的。苹果无论在哪个国家买质量都一样。我们的课程产品可复制化。 ...
    念美美阅读 117评论 0 1