如何为removeFromSuperview设置动画

时间:2012-05-22 11:15:20

标签: objective-c ios uiviewanimation catransition

我通过以下方式为子视图的外观设置了动画:

CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionReveal;
[webView.layer addAnimation:transition forKey:nil];

[self.view addSubview:webView];

但现在我要删除我的subView。如何添加动画来执行此操作?像其他CATransition一样?什么时候加?在addSubview之前或之后?

1 个答案:

答案 0 :(得分:22)

您可以先在animationEndListener来电removeFromSuperView

进行动画制作
[UIView animateWithDuration:0.5
    delay:1.0
    options: UIViewAnimationOptionCurveEaseOut
    animations:^{
        yourView.alpha = 0;
    }completion:^(BOOL finished){
        [yourView removeFromSuperview];
    }];