在View中添加一个加载动画
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:view];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = view.bounds;
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:view.bounds];
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = 2;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
[view.layer addSublayer:shapeLayer];
//任何CABasicAnimation 的@keyPath 为确定的, 此处为strokeEnd
//其他keyPath 参考[Ansel_m 的博客](http://blog.csdn.net/majiakun1/article/details/46426727)
CABasicAnimation *pathAnima = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnima.duration = 1.0f;
pathAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnima.fromValue = @0.05f;
pathAnima.toValue = @1.0f;
pathAnima.repeatCount = 100;
pathAnima.fillMode = kCAFillModeForwards;
pathAnima.removedOnCompletion = NO;
[shapeLayer addAnimation:pathAnima forKey:@"strokeEndAnimation"];
使用CAShapeLayer 的 转圈圈动画
最新推荐文章于 2021-02-06 20:52:27 发布