How to animate CAShapeLayer path and fillColor

匿名 (未验证) 提交于 2019-12-03 01:52:01

问题:

How to animate CAShapeLayer path and fillColor?

How to animate strokeEnd to show the path being drawn? and how to animate fillColor?

回答1:

To animate path

  //setup the CAShapeLayer myShapeLayer.strokeColor = [[UIColor blueColor] CGColor]; myShapeLayer.lineWidth = 5; myShapeLayer.fillColor = [[UIColor yellowColor] CGColor];    //Display it! [self.view.layer addSublayer:myShapeLayer];  //Animate path CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation.duration = 1.5f; pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; pathAnimation.repeatCount = 10; pathAnimation.autoreverses = YES; [myShapeLayer addAnimation:pathAnimation forKey:@"strokeEnd"];  //Animate colorFill CABasicAnimation *fillColorAnimation = [CABasicAnimation animationWithKeyPath:@"fillColor"]; fillColorAnimation.duration = 1.5f; fillColorAnimation.fromValue = (id)[[UIColor clearColor] CGColor]; fillColorAnimation.toValue = (id)[[UIColor yellowColor] CGColor]; fillColorAnimation.repeatCount = 10; fillColorAnimation.autoreverses = YES; [myShapeLayer addAnimation:fillColorAnimation forKey:@"fillColor"]; 

I hope this helps :)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!