如何使用Delay设置显式CA动画的最终值

时间:2014-07-06 14:17:02

标签: ios xcode ios7 core-animation quartz-graphics

我有一个明确的动画,我想设置最终值,以便对象停留在终点。但是我如何在延迟动画中实现这一点:以下是代码:

CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnimation.duration = 0.3;
    moveAnimation.cumulative = YES;
    moveAnimation.repeatCount = 1;

    // Bounce
    [moveAnimation setValues:[NSArray arrayWithObjects:
                         [NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:0 withIndex:i]],
                         [NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius + 10 withIndex:i]],
                         [NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius - 5 withIndex:i]],
                         [NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]], nil]];

    [moveAnimation setKeyTimes:[NSArray arrayWithObjects:
                           [NSNumber numberWithFloat:0],
                           [NSNumber numberWithFloat:0.5],
                           [NSNumber numberWithFloat:0.75],
                           [NSNumber numberWithFloat:1.0], nil]];

    [moveAnimation setTimingFunctions:[NSArray arrayWithObjects:
                                       [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]];



    moveAnimation.beginTime = CACurrentMediaTime() + 1 + (0.1 * i);


    [layer addAnimation:opacityAnimation forKey:@"opacityAnimationUp"];
    [layer addAnimation:moveAnimation forKey:@"moveAnimationUp"];

// That's not working correctly because of the delay
    [layer setOpacity:1.0];
    [layer setPosition:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]];

谢谢!

来自德国的问候, 克里斯

1 个答案:

答案 0 :(得分:2)

看起来唯一缺少的是向后填充模式。即使实际动画被延迟,这也会导致动画在添加后立即显示第一个值:

moveAnimation.fillMode = kCAFillModeBackwards;