XCode - 如何停止CAKeyframeAnimation

时间:2015-09-25 12:34:48

标签: ios xcode animation

我的应用程序中有一个CAKeyframeAnimation。我想在cirlce中移动图像,这就是我使用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"];

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

我该怎么做?

非常感谢

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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