Reputation: 1069
Currently i am moving a png image using CAKeyframeAnimation along a path for 30 seconds. Is there any way to stop this moving image in between 0-30 seconds on tapping a button?
Upvotes: 3
Views: 2684
Reputation: 407
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
}
Upvotes: 3
Reputation: 26390
Did you try
[view.layer removeAnimationForKey:kFrameAnimationKey];
Upvotes: 1
Reputation: 5117
This will remove the animation...
[yourView.layer removeAllAnimations];
Upvotes: 6