OGeek|极客世界-中国程序员成长平台

标题: ios - 动画停止时如何停止恢复到原始值 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:26
标题: ios - 动画停止时如何停止恢复到原始值

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

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



Best Answer-推荐答案


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

关于ios - 动画停止时如何停止恢复到原始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16852807/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4