动画执行结束后 执行指定操作

- (void)onClick:(id)sender
{
    UIButton *helpImageBtn = (UIButton *)sender;
    [UIView animateWithDuration:1.25f
                     animati*****:^{
                         // fade out
                         helpImageBtn.alpha = 0.0f;
                     }
                     completion:^(BOOL finished){
                         // remove from super view on animation finished
                         if (helpImageBtn.superview)
                             [helpImageBtn removeFromSuperview];
                     }];
}



注意,这种块动画编程只支持iOS4.0以上的版本,如果你要兼容以前的版本,需要改用[UIView beginAnimati*****:nil context:nil]的相应写法:

- (void)onClick:(id)sender
{
    UIButton *helpImageBtn = (UIButton *)sender;
    self.retainedHelpImageBtn = helpImageBtn;
 
    [UIView beginAnimati*****:nil context:nil];
    // fade out
    helpImageBtn.alpha = 0.0f;
    // set animation did stop selector
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimati*****];
}
 
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if (self.retainedHelpImageBtn.superview)
        [self.retainedHelpImageBtn removeFromSuperview];
}
原文地址:https://www.cnblogs.com/gaoxiao228/p/2553336.html