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

- (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];
}

 

posted @ 2012-06-18 11:47  高笑228  阅读(192)  评论(0编辑  收藏  举报