Search code examples
cocoacore-animationquartz-graphics

Can I animate an NSBezierPath within a CALayer?


I have read the Core Animation Cook Book and Core Animation Programming Guide from Apple, but I'm not quite sure about some of the details.

Do I always have to animate a complete CALayer, or can I animate stuff within a CALayer?

If I have drawn a NSBezierPath within a layer and I want to animate/move this to another position, how do I do that? Is there an example of this that you could point me to?


Solution

  • Normally, you do animate the CALayer as a whole for best performance. If all you're looking to do is to shift the position of your Bezier path, you can simply animate the position or frame properties of your CALayer.

    If you want to change the shape of a vector path, I'd recommend looking at the new CAShapeLayer, where you can animate between one CGPath and another by using the path property on the layer. Joe Ricioppo has some sample code you can look at for this here.

    Beyond that, you'll need to redraw the layer if you want to update its contents, rather than its base properties like position, scale, rotation, etc.