0

Possible Duplicate:
Cancel a UIView animation?

i need to stop an UIView animation. I know i can use [object.layer removeAllAnimations]; but this doesn't stop the animation, but "skip" it. So, if my original animation is :

[UIView animateWithDuration:8.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^ (void) {
        [ingredient setFrame:CGRectMake(20, 200, 34, 45)];
    } completion:^ (BOOL finished) {
        NSLog(@"Completed");
    }];

the object ingredient will have the frame that would have if the animation had finished. Instead, i want the object STOP in specific point, without the animation complete.

Community
  • 1
  • 1
Andrea Mario Lufino
  • 7,921
  • 12
  • 47
  • 78
  • If you turn off the device, all animations will stop. –  Oct 30 '12 at 14:01
  • possible duplicate of [Cancel a UIView animation?](http://stackoverflow.com/questions/554997/cancel-a-uiview-animation) and [How to stop an UIView animation](http://stackoverflow.com/questions/7204602/how-to-stop-an-uiview-animation) –  Oct 30 '12 at 14:02
  • 1
    Not a duplicate, this question is regarding 'pausing' an animation, not cancelling it. – WDUK Oct 30 '12 at 17:59

1 Answers1

1

If you want to pause, but don't intend to start again, try:

CALayer *objectPresentationLayer = [object.layer presentationLayer];
object.layer.transform = objectPresentationLayer.transform;
[object.layer removeAllAnimations];

If you want to pause and resume animations, check this out from the Apple Q&A: https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html

WDUK
  • 18,870
  • 3
  • 64
  • 72