使用动画从SuperView中删除UIVIew [英] Remove UIVIew from SuperView with Animation

查看:158
本文介绍了使用动画从SuperView中删除UIVIew的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以动画添加一个UIView到我的应用程序,它看起来非常漂亮所以谢谢你苹果。

I can animate the addition of a UIView to my app, it looks very pretty so thank you apple.

但是,如何动画删除此视图从超级视图?

However, how do I animate the removal of this view from the super view?

我正在使用:

CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionReveal];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myview layer] addAnimation:animation forKey:kCATransitionReveal];

为in转换添加动画效果...如何为out

to animate the "in" transition ... how do you animate the "out" transition????

推荐答案

动画处理视图,使其移离屏幕/收缩/展开/淡出,然后在动画结束时进行实际删除。

Animate your view so it moves offscreen/shrinks/expands/fades, then do the actual removal when the animation ends.

您可以通过改变beginAnimations / commitAnimations块之间的视图(位置/大小/偏移)的属性来实现。 UIKit然后将在指定的时间为这些属性设置动画。

You can do this by altering the properties of the view (position/size/offset) between a beginAnimations/commitAnimations block. UIKit will then animate these properties over the time specified.

例如:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
view.transform = 
  CGAffineTransformMakeTranslation(
    view.frame.origin.x, 
    480.0f + (view.frame.size.height/2)  // move the whole view offscreen
  );
background.alpha = 0; // also fade to transparent
[UIView commitAnimations];

在动画结束通知中,您可以移除该视图。

In the animation end notification you can then remove the view.

这篇关于使用动画从SuperView中删除UIVIew的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆