sach
sach

Reputation: 1069

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 image in between 0-30 seconds on tapping a button?

Upvotes: 3

Views: 2684

Answers (3)

Radagast the Brown
Radagast the Brown

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

visakh7
visakh7

Reputation: 26390

Did you try

[view.layer removeAnimationForKey:kFrameAnimationKey];

Upvotes: 1

Chandan Shetty SP
Chandan Shetty SP

Reputation: 5117

This will remove the animation...

[yourView.layer removeAllAnimations];

Upvotes: 6

Related Questions