【问题标题】:UIView Animation With Child Views带有子视图的 UIView 动画
【发布时间】:2015-02-18 15:31:45
【问题描述】:

我有一个 UIView(称为通知视图),里面有一个滚动视图(使用 addSubView)。我想将此视图显示为带有一些动画的弹出窗口。所以在开始时我将它的高度设置为 0,在动画块中我将它的高度设置为所需的数字。当我想隐藏这个视图时,我在动画块中将它的高度设置为 0。它工作正常。问题是

  • 通知视图的子视图首先出现,然后通知视图完成其动画。
  • 当我想隐藏它时,通知视图首先完成其动画直到 height=0,然后子视图立即消失。

我想为通知视图创建收缩/扩展效果。为了显示弹出窗口,我正在使用以下动画块

[UIView animateWithDuration:1.0
                     animations:^{
                         notificationParentView.frame = CGRectMake(50, 52, 220, 200);
                         downArrowIcon.transform = CGAffineTransformMakeRotation(M_PI);
                     }];

要隐藏此弹出窗口,请运行以下代码

[UIView animateWithDuration:1.0
                     animations:^{
                         notificationParentView.frame = CGRectMake(50, 52, 220, 0);
                         downArrowIcon.transform = CGAffineTransformMakeRotation(0);
                     }completion:^(BOOL finished){
                         [notificationParentView removeFromSuperview];
                     }];

notificationParentView 可以很好地扩展和收缩,但它的子视图不会随着它们的父视图扩展/收缩。即notificationParentView。我有什么明显的遗漏吗?

【问题讨论】:

    标签: ios objective-c uiview uiviewanimation


    【解决方案1】:

    你可以使用 CGAffineTransform

    //Appear animation
    notificationParentView.transform = CGAffineTransformConcat(CGAffineTransformMakeScale(0, 1), CGAffineTransformMakeRotation(M_PI))    // Set to hidden state
    [UIView animateWithDuration:1.0
                         animations:^{
                             notificationParentView.transform = GAffineTransformIdentity;// Set back to normal, displaying state
                         }];
    //disappear
    [UIView animateWithDuration:1.0
                         animations:^{
    notificationParentView.transform = CGAffineTransformConcat(CGAffineTransformMakeScale(0, 1), CGAffineTransformMakeRotation(M_PI)); //Back to hidden state.                          
                             }];
    

    【讨论】:

    • 那么意味着我应该删除动画块吗?
    • 不,在你的动画块中使用这个代码。但是,当您显示它时,您可能希望在块之外设置缩放变换。
    • @Ans 应该是这样的。
    • 你写了“它应该看起来像这样。”我以为你错过了几行写..
    • 不,我认为它应该可以工作,但你可能需要适应你的代码风格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多