Update a Label only after UIButton animation is complete?
I've used the code in an IBAction (button press) method:
CABasicAnimation *rotateButton; //don't forget to release
rotateButton = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotateButton.from开发者_如何学CValue = [NSNumber numberWithFloat:0];
rotateButton.toValue = [NSNumber numberWithFloat:((720*M_PI)/180)];
rotateButton.duration = 0.75;
rotateButton.repeatCount = 1;
[sender addAnimation:rotateButton forKey:@"720"];
and have a label that I want updated only after this is complete. I am wondering if there is a simple example anyone can provide me with to have the label only update when this is completed and not when the method is complete. I know you cannot use "@selector(animationDidStop:finished:context:)" because apple doesn't like it. Help from anyone? Please and Thank you!
Why not just use a UIView animation block?
[UIView animateWithDuration:0.75 delay:0 options:0 animations:^{
theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180);
} completion:^{
theLabel.text = @"Whatever";
}];
If you need pre-4.x compatibility, use the old form, with the UIView class method +setAnimationDidStopSelector:
, like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDidStopSelector:@selector(someMethodInWhichYouSetTheLabelText)];
theButton.transform = CGAffineTransformMakeRotation((720*M_PI)/180);
[UIView commitAnimations];
I know you cannot use "@selector(animationDidStop:finished:context:)"
Actually you can, just give it another name so it will not clash with Apple internal method
About your problem:
CAAnimation Class Reference
delegate
Specifies the receiver’s delegate object.
animationDidStop:finished:
Called when the animation completes its active duration or is removed from the object it is attached to.
精彩评论