UIView animation completion callback?
Can I setup a function to be called once my animatio开发者_如何转开发n is complete? I want to fade a UIView
and then remove it from the superView
.
Animation blocks were introduced in iOS4. Apple recommends you use these, and the new methods mostly ask for completion blocks which replace callbacks. For example:
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
[myView setAlpha:0.0f];
}
completion:^(BOOL finished) {
[myView removeFromSuperview];
}];
Yes, that's easy:
When you configure your animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myAnimationStopped:finished:context:)];
And define your method like:
-(void)myAnimationStopped:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context {
// fancy code here
}
Doesn't have to be self
and that method, of course.
精彩评论