繁体   English   中英

UIView动画完成回调?

[英]UIView animation completion callback?

动画制作完成后,我可以设置要调用的功能吗? 我想淡出UIView ,然后将其从superView删除。

动画块是在iOS4中引入的。 Apple建议您使用这些,新方法通常会要求使用完成块来代替回调。 例如:

[UIView animateWithDuration:0.5f
                      delay:0.0f
                    options:UIViewAnimationCurveEaseInOut
                 animations:^{
                   [myView setAlpha:0.0f];
                 }
                 completion:^(BOOL finished) {
                   [myView removeFromSuperview];
                 }]; 

是的,这很容易:

配置动画时

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myAnimationStopped:finished:context:)];

并定义您的方法,例如:

-(void)myAnimationStopped:(NSString *)animationID 
                 finished:(NSNumber *)finished
                  context:(void *)context {
   // fancy code here
}

当然,不必一定是self ,也不需要那种方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM