2

I'm trying to find a way to animate the color of the stroke that I am creating

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) 

What I want to achieve is: while it's being created (I'm creating it over a duration of 1 seconds), the color will animate itself.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Roi Mulia
  • 5,626
  • 11
  • 54
  • 105
  • This looks like an exact duplicate of your previous question http://stackoverflow.com/questions/26602171/swift-animate-cashapelayer-stroke-color. If you don't get answers then try to improve the question, provide more information, ... but don't simply repeat it. – Martin R Oct 28 '14 at 09:23
  • @MartinR i taught it was deleted oh. can i delete this one martin? – Roi Mulia Oct 28 '14 at 09:30

1 Answers1

1

Found out the solution. Enjoy. After you create the CAShapeLayer of course :

        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")
Roi Mulia
  • 5,626
  • 11
  • 54
  • 105