iOS堆栈动画系列

时间:2014-11-17 15:04:44

标签: ios cabasicanimation

我想在系列中创建一组动画。 例如

  • 淡入2秒

  • 旋转2秒

  • 淡出2秒

实现这一目标的最佳方法是什么?我试图使用CAAnimation组,但似乎并行动画了它的动画数组。我想做一个动画1然后做动画2然后做动画3(系列)

2 个答案:

答案 0 :(得分:3)

如今,您通常会通过UIView使用animateKeyframesWithDuration块动画。指定动画持续时间为6秒,然后向addKeyframeWithRelativeStartTime添加三个调用,分别从相对开始时间0,0.333和0.666开始,每个调用持续时间为0.333,在这三个动画块中,执行适当的动画。

答案 1 :(得分:2)

您应该将基于块的动画用于所有这类动画。

对于像这样的动画,animateKeyFrames块将是完美的......

// set duration for the entire sequence of animations
[UIView animateKeyFramesWithDuration:6
                               delay:0
                             options:0
                          animations:^{
                              // add fade in keyframe
                              // starts at 0% lasts for 33% of animation
                              [UIView addKeyFrameWithRelativeStartTime:0
                                                      relativeDuration:0.333
                                                            animations:^{
                                                                view.alpha = 1.0;
                                                            }];
                              // add rotation key frame
                              // starts at 33% lasts for 33% of animation
                              [UIView addKeyFrameWithRelativeStartTime:0.333
                                                      relativeDuration:0.333
                                                            animations:^{
                                                                view.transform = CGAffineTransformMakeRotation(rotationAngle);
                                                            }];
                              // add fade out key frame
                              // starts at 66% lasts for 33% of animation
                              [UIView addKeyFrameWithRelativeStartTime:0.666
                                                      relativeDuration:0.333
                                                            animations:^{
                                                                view.alpha = 0.0;
                                                            }];
                          }
                          completion:nil];