How can I pause a currently running animation?

主宰稳场 提交于 2019-12-11 14:57:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!