开发者

Stopping CAKeyframeAnimation in middle

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜