2015-09-25 39 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移回位置的動畫(故事板)前。我希望它停止在動畫中的當前位置。