开发者

Stopping CAKeyframeAnimation in middle

开发者 https://www.devze.com 2023-02-27 05:19 出处:网络
Currently i am moving a png image using CAKeyframeAnimation along a path for 30 seconds. Is there any way to stop this moving i开发者_如何学编程mage in between 0-30 seconds on tapping a button?This wi

Currently i am moving a png image using CAKeyframeAnimation along a path for 30 seconds. Is there any way to stop this moving i开发者_如何学编程mage in between 0-30 seconds on tapping a button?


This will remove the animation...

[yourView.layer removeAllAnimations];


Well... do you want to stop the animation or would you simply like to pause/resume? If you'd like to pause, then there is something like this:

func pause(){
    pausedTime = foo.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
    foo.layer.speed = 0
    foo.layer.timeOffset = pausedTime!
}
func play(){
    pausedTime = foo.layer.timeOffset
    foo.layer.speed = 1.0
    foo.layer.timeOffset = 0
    let timeSincePause = foo.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime!
    foo.layer.beginTime = timeSincePause
}


Did you try

[view.layer removeAnimationForKey:kFrameAnimationKey];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号