CABasicAnimation不改变笔画颜色

时间:2017-05-26 13:57:25

标签: ios swift cabasicanimation

我在viewDidLoad()中有以下代码来绘制一个圆,然后为其笔触的颜色变化设置动画:

let leftCirclePath = UIBezierPath(arcCenter: CGPoint(x: 32, y: view.bounds.height-30), radius: CGFloat(20), startAngle: CGFloat(0), endAngle: CGFloat(Double.pi*2), clockwise: true)
leftShapeLayer = CAShapeLayer()
leftShapeLayer.path = leftCirclePath.cgPath
leftShapeLayer.fillColor = UIColor.black.cgColor
leftShapeLayer.strokeColor = UIColor.white.cgColor
leftShapeLayer.lineWidth = 3.0
view.layer.addSublayer(leftShapeLayer)

let leftAnimation = CABasicAnimation(keyPath: "strokeColor")
leftAnimation.fromValue = UIColor.white.cgColor
leftAnimation.toValue = UIColor.red.cgColor
leftAnimation.duration = 1
leftAnimation.repeatCount = 5
leftAnimation.autoreverses = true
leftShapeLayer.add(leftAnimation, forKey: "strokeColor")

绘制的形状很好,但是它的笔触没有颜色变化。有谁知道这个问题是什么?感谢。

0 个答案:

没有答案