动画停止时如何停止恢复到原始值

时间:2013-05-31 08:16:03

标签: ios objective-c cocoa-touch

我使用核心动画制作动画视图。动画停止后,视图将恢复为原始值。我怎么能停止恢复? 这是我的代码

   #define p(x,y) CGPointMake(x,y)
   #define v valueWithCGPoint
    ...
    CGPoint rectL=p(463, 473);
    CGPoint rectR=p(503, 473);
    NSValue *valueL = [NSValue v:rectL];
    NSValue *valueR = [NSValue v:rectR];
    NSArray *firstArray=@[valueL,valueR,valueL,valueR,valueL,valueR,valueL,valueR];

    CAKeyframeAnimation * theAnimation;

    // Create the animation object, specifying the position property as the key path.
    theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    theAnimation.values=firstArray;
    theAnimation.duration=5.0;
    //theAnimation.calculationMode= kCAAnimationLinear;
    // Add the animation to the layer.
    [self.boView.layer addAnimation:theAnimation forKey:@"moveBackAndForth"];

2 个答案:

答案 0 :(得分:1)

在添加动画之前设置最终值。动画包含所需的起始值,因此它将继续按照您的意愿工作。

答案 1 :(得分:0)

设置 CAKeyframeAnimation 属性removedOnCompletion = NO;

theAnimation.removedOnCompletion = NO;