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];
精彩评论