views:

275

answers:

2

I have a Core Animation running and want to pause it when a button is pressed. So there is a method -pauseAnimation. When the animation is paused, I want the animated view to stay in the state as it currently was while animating. i.e. if a view moves from top left to bottom right, and somewhere in the middle the animation is paused, the view should stay in the middle. Is there a way to do this?

as far as i can remember there is an setAnimationsEnabled=NO option, but that doesn't work when the animation runs, right?

+1  A: 

You can do this by disabling animations and then setting the model layers' values to the presentation layers' values (for all properties that define your animation).

eg. layer.transform = layer.presentationLayer.transform;

Resuming the animation = re-enable animations and animate from current positions to the desired final positions (you might have to adjust curves, etc to get something acceptable).

Andrew Pouliot
how would I set the model layers values to the presentation layers values? myView.transform = myview.layer.transform?
Thanks
If you're working with UIViews, you'll need to call view.layer to get access to the layer, so view.layer.transform = view.layer.presentationLayer.transform.
Andrew Pouliot
+1  A: 

You can pause layer animations by setting the speed of the animation to zero, see How to pause the animation of a layer tree.

Douglas