Roi*_*lia 2 cashapelayer uiviewanimation swift
我正试图找到一种方法来动画我正在创建的笔画的颜色
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)
Run Code Online (Sandbox Code Playgroud)
我想要实现的是:当它被创建时(我创建它持续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")
Run Code Online (Sandbox Code Playgroud)