IPhone SDK - how can I find out when the animation is over?

I start the animated extension when I touch the image, and then reduce it to its normal size when it is released. With setAnimationBeginsFromCurrentState: YES, the zoom effect is nice and smooth if you lift part of your finger through the animation.

However, what I want to do is to โ€œlockโ€ the larger size in place if you touch the image long enough to complete the animation, but let it shrink as usual if you release it prematurely.

Is there a way to find out if there is an animation at the moment, or is a specific animation completed?

I suppose I can possibly do this with the performSelector: afterDelay: call in touchesStarted function, with a delay equal to the length of the animation and cancel it if touchEEnd arrives too soon, but I canโ€™t imagine that this is the best way ...

+5
source share
3 answers
- (void)animateStuff {
    [UIView beginAnimations:@"animationName" context:nil];
    [UIView setAnimationDelegate:self];
    [self.view doWhatever];
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID
                finished:(NSNumber *)finished
                 context:(void *)context
{
    if ([finished boolValue]) {
        NSLog(@"Animation Done!");
    }
}
+13
source

Another possibility:

 [UIView animateWithDuration:0.3 animations:^{

      myView.transform = CGAffineTransformMakeRotation(M_PI);

 }completion:^(BOOL finished) {

      NSLog(@"Animation complete!");
 }];
+1
source

I think the "+ (void) setAnimationDidStopSelector: (SEL) selector" should do what you want. It will call this selector in your delegate after the animation is complete.

0
source

All Articles