我正试图找到一种方法来设置我正在创建的笔画颜色的动画
circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
circleLayer.lineCap = kCALineCapRound
circleLayer.fillColor = UIColor.clearColor().CGColor
CABasicAnimation fill = CABasicAnimation.
circleLayer.strokeColor = UIColor(red: 0.4, green: 1.0, blue: 0.2, alpha: 0.5).CGColor
circleLayer.lineWidth = 20.0;
circleLayer.lineJoin = kCALineJoinRound
// Don't draw the circle initially
circleLayer.strokeEnd = 0.0
// Add the circleLayer to the view's layer's sublayers
layer.addSublayer(circleLayer)
我想要实现的是:当它被创建时(我在1秒的时间内创建它),颜色将自动生成。
答案 0 :(得分:1)
找到解决方案。请享用。在创建CAShapeLayer之后:
let animcolor = CABasicAnimation(keyPath: "strokeColor")
animcolor.fromValue = UIColor.greenColor().CGColor
animcolor.toValue = UIColor.orangeColor().CGColor
animcolor.duration = 1.0;
animcolor.repeatCount = 0;
animcolor.autoreverses = true
circleLayer.addAnimation(animcolor, forKey: "strokeColor")