1

I have a CALayer circle that I would like to animate the transform. I want it to start off at 0 and then slowly get larger to its original size. Here is what I have:

expandingCircleLayer = CAShapeLayer()
let radius: CGFloat = (self.view?.bounds.width)! * 0.10
expandingCircleLayer!.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 2.0 * radius, height: 2.0 * radius)  , cornerRadius: radius).CGPath
expandingCircleLayer!.fillColor = UIColor.redColor().CGColor

After the animation is completed, I would also like to run a block of code. I know this is possible with a SpriteNode, but I'm not too sure how to do it with a CALayer.

Please Help!

OriginalAlchemist
  • 391
  • 1
  • 7
  • 28
  • This might be helpful to you! http://stackoverflow.com/questions/13734984/ios-view-transform-animation I ll had find out with just google a bit. – Milan V. Apr 07 '16 at 10:05

1 Answers1

1

I've just do this circular node using a nice code block find here :Circular progress timer/bar in iOS using SpriteKit

The class structure is very simple:

import SpriteKit

class CircularProgressNode : SKShapeNode
{
   private var radius: CGFloat!
   private var startAngle: CGFloat!

   init(radius: CGFloat, color: SKColor, width: CGFloat, startAngle: CGFloat = CGFloat(M_PI_2)) {
       super.init()

       self.radius = radius
       self.strokeColor = color
       self.lineWidth = width
       self.startAngle = startAngle

       self.updateProgress(0.0)
   }

   required init(coder aDecoder: NSCoder) {
       fatalError(“init(coder:) has not been implemented”)
   }

   func updateProgress(percentageCompleted: CGFloat) {
       let progress = percentageCompleted <= 0.0 ? 1.0 : (percentageCompleted >= 1.0 ? 0.0 : 1.0 - percentageCompleted)
       let endAngle = self.startAngle + progress * CGFloat(2.0 * M_PI)

       self.path = UIBezierPath(arcCenter: CGPointZero, radius: self.radius, startAngle: self.startAngle, endAngle: endAngle, clockwise: true).CGPath
   }
}
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • Im not trying to do a circular progress bar, i just want to animate the transform of a CAShapeLayer. Similar to what this would do for a UIView: UIView.animateWithDuration(0.5) { view?.transform = CGAffineTransformMakeScale(1.0, 1.0) } – OriginalAlchemist Apr 13 '16 at 06:40
  • In you question you ask if it's possibile with spritenode (spritekit). The SKShapeNode is a CAShapeLayer counterpart. – Alessandro Ornano Apr 13 '16 at 07:21
  • Oh I'm sorry for the confusion. I said that I know that its possible with a SpriteNode but want to know how to do it with a CAShapeLayer. – OriginalAlchemist Apr 13 '16 at 07:39