【问题标题】:Remove UIVIew from SuperView with Animation使用动画从 SuperView 中删除 UIVIew
【发布时间】:2009-03-09 21:26:29
【问题描述】:

我可以为我的应用添加 UIView 动画,它看起来非常漂亮,所以谢谢苹果。

但是,如何为从超级视图中移除此视图设置动画?

我正在使用:

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

为“in”过渡设置动画...如何为“out”过渡设置动画????

【问题讨论】:

    标签: iphone cocoa-touch uiview core-animation


    【解决方案1】:

    为您的视图设置动画,使其移出屏幕/缩小/展开/淡入淡出,然后在动画结束时进行实际移除。

    您可以通过在 beginAnimations/commitAnimations 块之间更改视图的属性(位置/大小/偏移)来做到这一点。 UIKit 将在指定的时间内为这些属性设置动画。

    例如类似的东西;

    [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];
    

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

    【讨论】:

    • 谢谢!我想这是我的问题:我如何为视图设置动画以显示它移出屏幕?
    • 啊……谢谢,我真的很感激。很奇怪,屏幕外的过渡没有融入其中。感谢您的帮助!
    猜你喜欢
    • 2020-04-28
    • 2021-12-31
    • 2019-08-09
    • 2019-04-08
    • 2023-03-11
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多