问题
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:
You can pause layer animations by setting the speed of the animation to zero, see How to pause the animation of a layer tree.
回答2:
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).
来源:https://stackoverflow.com/questions/1152918/how-can-i-pause-a-currently-running-animation