Question

I'm playing around with C4, and can't seem to figure out why my shapes don't animate. If I create a shape like so:

self.theShape = [C4Shape ellipse:CGRectMake(100, 100, 2, 2)];

... and later call

[theShape setFrame:CGRectMake(200, 200, 50,50)];

The shape doesn't change size. The implementation suggests that it should, but I'm not seeing it. Is there anything I'm doing wrong? Is it because I'm not updating the canvas?

Was it helpful?

Solution

In C4, calling setFrame: on a C4Shape object will not scale it.

The reason being is that changing the frame of a CAShapeLayer's view will not change the underlying bezier shape itself... Unlike calling the same thing on an image. UIKit will scale images, and other content, but will not scale beziers (as far as I know)...

So, if it's a rect, call:

[theShape rect:aNewFrame]

or if its an ellipse, call:

[theShape ellipse:aNewFrame]

This approach constructs a new shape and then leverages Core Animations ability to implicitly animate the transition between the old shape path and the new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top