【问题标题】:UIView: one animation with multiple changesUIView:一个动画有多个变化
【发布时间】:2011-12-02 13:21:23
【问题描述】:

我需要在 UIView 上同时制作动画。我想同时改变大小和位置。我试试这段代码:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationBeginsFromCurrentState:NO];

[openingElement setFrame:elementFrame];

[UIView commitAnimations];

此代码有效,但 UIView 动画分两步(移动和调整大小后),我想一起做。 是否可以制作多个更改的动画?

【问题讨论】:

    标签: objective-c ios cocoa-touch ipad uiview


    【解决方案1】:

    可以在一个动画中进行多项更改。在 UIView 上,您可以同时对 alpha、bounds、frame、center、transform 和 backgroundColor 进行动画更改。

    如果您对 frame 属性的动画有问题,请尝试为 center 和 bounds 设置动画。

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationBeginsFromCurrentState:NO];
    
    [openingElement setBounds:newBounds];
    [openingElement setCenter:newCenter];
    
    [UIView commitAnimations];
    

    【讨论】:

      【解决方案2】:

      试试这个

      [UIView setAnimationBeginsFromCurrentState:YES];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多