【问题标题】:XCode - how to stop a CAKeyframeAnimationXCode - 如何停止 CAKeyframeAnimation
【发布时间】:2015-09-25 12:34:48
【问题描述】:

我的应用中有一个 CAKeyframeAnimation。我想在圆圈中移动图像,这就是我使用 CAKeyframeAnimation 的原因。这是我当前的代码:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation        animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;    
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 5.0;
pathAnimation.repeatCount = 0;

CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, 10, 10);

CGRect rectangle = CGRectMake(69,211,239,243);

CGPathAddEllipseInRect(curvedPath, NULL, rectangle);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

[imgView.layer addAnimation:pathAnimation forKey:@"moveTheObject"];

现在我想如果用户点击显示动画停止并且图像是它所在的当前位置。

我该怎么做?

非常感谢

【问题讨论】:

    标签: ios xcode animation


    【解决方案1】:

    使用[imgView.layer removeAnimationForKey:@"moveTheObject"];[imgView.layer removeAllAnimations];

    【讨论】:

      【解决方案2】:

      是的,但是 ImageView 会移回动画之前的位置(故事板)。我希望它停在动画中的当前位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-23
        • 1970-01-01
        • 2011-09-26
        • 1970-01-01
        • 2012-12-07
        • 2014-04-14
        相关资源
        最近更新 更多