2

我使用核心动画来制作动画视图。当动画停止时,视图将恢复到原来的值。我怎样才能停止恢复?这是我的代码

   #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"];
4

2 回答 2

1

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

于 2013-05-31T08:19:03.363 回答
0

设置CAKeyframeAnimation属性removedOnCompletion = NO;

theAnimation.removedOnCompletion = NO;
于 2013-05-31T08:18:25.863 回答