2015-09-25 40 views
0

我在我的应用程序中有一个CAKeyframeAnimation。我想移动一个图像,这就是我使用CAKeyframeAnimation的原因。这里是我当前的代码:XCode - 如何停止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"]; 

,现在我想,如果用户点击显示动画停止,图像是当前位置在哪里。

我该怎么做?

非常感谢

回答

0

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

0

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