- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CAShapeLayer *layer =[CAShapeLayer layer];
layer.lineWidth = 10;
layer.fillColor = [UIColor clearColor].CGColor;
layer.strokeColor =[UIColor redColor].CGColor;
layer.frame = CGRectMake(50, 50, 100, 100);
layer.lineCap = kCALineCapRound;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50) radius:50 startAngle:DEGREES_TO_RADIANS(270) endAngle:DEGREES_TO_RADIANS(180) clockwise:YES];
layer.path = path.CGPath;
[self.view.layer addSublayer:layer];
//画一个圆
CAKeyframeAnimation *strokeEndAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeEnd"];
strokeEndAnimation.duration = 0.5;
strokeEndAnimation.values = @[@0.0, @1];
strokeEndAnimation.keyTimes = @[@0.0,@1];
//旋转2圈
CABasicAnimation *rotaAni = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotaAni.fromValue = @(DEGREES_TO_RADIANS(0));
rotaAni.toValue = @(DEGREES_TO_RADIANS(720));
rotaAni.autoreverses = YES;
//最后填充颜色
//创建一个CABasicAnimation对象
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
//设置颜色
animation.toValue=(id)[UIColor blackColor].CGColor; //必须要用黑色
CAAnimationGroup *group = [CAAnimationGroup animation];
group.repeatCount = INFINITY;
group.duration = 2;
group.animations = @[strokeEndAnimation,rotaAni,animation];
[layer addAnimation:group forKey:nil];
}
仿网易评论加载动画
最新推荐文章于 2020-12-12 16:09:23 发布