如何在ipad中按顺序播放动画

时间:2011-01-01 10:44:41

标签: iphone ipad

我有两个动画,分别是layer1和layer2两个层,每个都有不同的路径。所以,我想知道如何按顺序播放它们。首先播放layer1的动画,然后播放layer2。

这是我的两个动画代码!

层1

    CALayer *layer1 = [CALayer layer];
    [self.layer addSublayer:layer1];
    CAKeyframeAnimation *animation1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    layer1.contents = (id)image1.CGImage;
    layer1.anchorPoint = CGPointZero;
    layer1.frame = CGRectMake(0.0f, 0.0f, image1.size.width, image1.size.height);
    animation1.path = path1;
    animation1.duration = 2.0f;
    animation1.calculationMode = kCAAnimationLinear;
    [layer1 addAnimation:animation1 forKey:@"position"];

二层

    CALayer *layer2 = [CALayer layer];
    [self.layer addSublayer:layer2];
    CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    layer2.contents = (id)image2.CGImage;
    layer2.anchorPoint = CGPointZero;
    layer2.frame = CGRectMake(0.0f, 0.0f, image2.size.width, image2.size.height);
    animation2.path = path2;
    animation2.duration = 2.0f;
    animation2.calculationMode = kCAAnimationLinear;
    [layer2 addAnimation:animation2 forKey:@"position"];

1 个答案:

答案 0 :(得分:2)

为第一个动画设置委托,并在animationDidStop:finished:委托方法中开始第二个动画。