Search code examples
objective-cxcodeiphone-sdk-3.0core-animation

how to stop core animation?


I am animating a button using core animation now on a certain condition I want to stop that animation how do I stop the animation?

here is the method to animate the button

-(void)animateButton:(UIButton *)btnName
{
    CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulseAnimation.duration = .5;
    pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
    pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulseAnimation.autoreverses = YES;
    pulseAnimation.repeatCount = FLT_MAX;

    [btnName.layer addAnimation:pulseAnimation forKey:nil];
}

Solution

  • From Core Animation Programming Guide

    Starting and Stopping Explicit Animations

    You start an explicit animation by sending a addAnimation:forKey: message to the target layer, passing the animation and an identifier as parameters. Once added to the target layer the explicit animation will run until the animation completes, or it is removed from the layer. The identifier used to add an animation to a layer is also used to stop it by invoking removeAnimationForKey:. You can stop all animations for a layer by sending the layer a removeAllAnimations message.