ios动画专题

iOS实现网络图加载时候显示的圆形进度器

2018-08-18  本文已影响39人  MR小锦
demo.gif

这是该demo的效果图

接下来我来详细说明一下这个的实现思路。

    //添加一层浅白色layer
    layer = [CAShapeLayer layer];
    //设置贝塞尔曲线
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50,50) radius:radius startAngle:0 endAngle:2*M_PI clockwise:YES];
    //设置layer属性
    layer.path = path.CGPath;
    layer.fillRule = kCAFillRuleEvenOdd;
    layer.fillMode = kCAFillModeForwards;
    layer.fillColor = [UIColor clearColor].CGColor;
    layer.strokeColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5f].CGColor;
    layer.lineWidth = radius*2;
    
    [imageView.layer addSublayer:layer];
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
    anim.duration = 4.f;
    anim.fromValue = @0;
    anim.toValue = @1;
    [layer addAnimation:anim forKey:nil];
}
最近一年比较颓废,没怎么更新简书。接下来我会每周写一篇文章,充实自己。希望读者能与我共同进步,交流指教。
上一篇 下一篇

猜你喜欢

热点阅读