我正试图找到一种方法,使我正在创建的笔划的颜色具有动画效果。
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秒),颜色将自动设置动画。
最佳答案
找到解决方案。享受吧。当然,在创建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")
关于swift - Swift-动画CAshapeLayer笔触颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26604578/