sooon
sooon

Reputation: 4888

CALayer animating the Bounds

Is it possible to animate the bounds of the CALayer on iPhone? How to implement that? Thanks!

Upvotes: 2

Views: 1671

Answers (2)

Matt Long
Matt Long

Reputation: 24486

Yes, it is possible.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[[self view] setBounds:CGRectMake(0.0f, 0.0f, 200.0f, 200.0f)];
[UIView commitAnimations];

This will animate a view controller's view from it's current bounds to a bounds of 200 x 200 over 1 second. It won't change the origin--just the size of the bounds rectangle. This is implicit animation by the way. If you want a more complicated animation, look at using CABasicAnimation and animating explicitly.

Upvotes: 1

tonklon
tonklon

Reputation: 6767

Are you trying to animate the visible part of an image inside a layer, were the layer itself maintains size and position?

That's what CAScrollLayer is made for. Use a CAScrollLayer in place of your current Layer and add image-rendering layerl as a subLayer to the CAScrollLayer. You can then use the transform property of the sublayer to achieve that effect.

Upvotes: 0

Related Questions