1

我有一个我正在尝试做的序列动画。它有两个步骤。

第 1 步:我选择图层并稍微改变视角,使图层的顶部看起来向后移动。sourceViewController.view.layer.transform CATransform3DMakePerspective(0, 0.003, CATransform3DIdentity);

第 2 步:我将比例更改为 80%,并将视角恢复正常。这使它像一个轻微的摆动缩小动画。

sourceViewController.view.layer.transform = CATransform3DScale(sourceViewController.view.layer.transform, 0.8, 0.8, 1);

sourceViewController.view.layer.transform CATransform3DMakePerspective(0, 0, sourceViewController.view.layer.transform);

我最大的问题是这个。我不能同时在图层上做 2 个动画。它会在第一次转换结束时自动开始,而不是同时进行。这可以通过 concat 解决,但由于我希望第 1 步顶部发生,因此该层将其保存状态,以便第 2 步可以发生,我不能将所有三个都连接起来。

如何创建在同一层上具有 1 个或多个变换的多步动画?就像我在下面的示例中所说的那样,它将跳过第 1 步并开始,就好像该步骤已经完成一样。我知道解释起来有点混乱。这是我的动画。

[UIView animateWithDuration:2.0
                        延迟:0.0
                        选项:UIViewAnimationCurveEaseIn
                     动画:^{
                         sourceViewController.view.layer.transform = CATransform3DMakePerspective(0, 0.003, sourceViewController.view.layer.transform);
                         [UIView animateWithDuration:1.0
                                               延迟:1.0
                                             选项:UIViewAnimationCurveEaseOut
                                          动画:^{
                                              sourceViewController.view.layer.transform = CATransform3DConcat(CATransform3DScale(sourceViewController.view.layer.transform, 0.8, 0.8, 1),CATransform3DMakePerspective(0, 0, sourceViewController.view.layer.transform));

                                          }
                                          完成:无];
                     }
                     完成:^(布尔完成){
                     }];

我已经用谷歌搜索并尝试了一切。必须有一种方法可以在同一层上执行连续动画,从最后一个精灵离开的地方开始。我传入的是图层而不是 CATransform3DIdentity,因为我读到身份恢复到起始状态,而不是图层转换到的位置。

4

2 回答 2

2

在第一个动画完成之前,您不想开始第二个动画。这就是完成块的用途。

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
    sourceViewController.view.layer.transform = CATransform3DMakePerspective(
        0, 0.003, sourceViewController.view.layer.transform);
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
        sourceViewController.view.layer.transform = CATransform3DConcat(
            CATransform3DScale(sourceViewController.view.layer.transform, 0.8, 0.8, 1),
            CATransform3DMakePerspective(0, 0, sourceViewController.view.layer.transform));
    } completion:nil];
}];
于 2012-10-06T18:20:37.913 回答
0

您需要将第二个动画嵌套在第一个的完成处理程序中

[UIView animateWithDuration:2.0
                        delay:0.0
                      options:UIViewAnimationCurveEaseIn 
                   animations:^{
                         sourceViewController.view.layer.transform = CATransform3DMakePerspective(0, 0.003, sourceViewController.view.layer.transform);
                     } 
                     completion:^(BOOL finished){
                                        [UIView animateWithDuration:1.0
                                                              delay:0.0
                                                            options:UIViewAnimationCurveEaseOut 
                                                         animations:^{
                                                               sourceViewController.view.layer.transform = CATransform3DConcat(CATransform3DScale(sourceViewController.view.layer.transform, 0.8, 0.8, 1),CATransform3DMakePerspective(0, 0, sourceViewController.view.layer.transform));
                                          } 
                                          completion:nil];
                     }];
于 2012-10-06T18:21:30.897 回答