Reputation: 23
I have a simple animation to make text flash that I want to stop when I call the method "labelDropped". Here is the animation code:
- (void)blinkAnimation:(NSString *)animationID finished:(BOOL)finished target:(UIView *)target
{
float speedFloat = .8;
[UIView beginAnimations:animationID context:target];
[UIView setAnimationDuration:speedFloat];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(blinkAnimation:finished:target:)];
if([target alpha] == 1.0f)
[target setAlpha:0.0f];
else
[target setAlpha:1.0f];
[UIView commitAnimations];
}
This method is called in the init method of my view as follows:
[self blinkAnimation:@"blinkAnimation" finished:YES target:infoLabel];
And finally, the code I use to stop the animations, which is not working. It is being called from a separate method called "labelDropped":
[self.layer removeAllAnimations];
I've even tried:
[infoLabel.layer removeAllAnimations];
...But it is not working either. Thanks for any help.
Upvotes: 1
Views: 4988
Reputation: 9122
My guess is even when you stop an animation, the completion handler gets called. So you end up starting the animation again.
Check the value of the finished parameter. If finished == NO, don't start the animation again. Just put this at the beginning of blinkAnimation:finished:target:
.
if (!finished) return;
Upvotes: 2