2013-07-18 41 views
0

我需要爲UIImageView從起點到終點添加無限動畫,然後從終點到起點添加無限動畫。 我想是這樣的:從起點CAKeyframeAnimation從頭到尾重複動畫

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
pathAnimation.calculationMode = kCAAnimationPaced; 
pathAnimation.fillMode = kCAFillModeForwards; 
pathAnimation.removedOnCompletion = NO; 
pathAnimation.duration = 2.0; 
pathAnimation.repeatCount = HUGE_VALF; 
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 

CGPoint endPoint = CGPointMake(320.0f - 30.0f, self.myImage.frame.size.height); 
CGMutablePathRef curvedPath = CGPathCreateMutable(); 
CGPathMoveToPoint(curvedPath, NULL, self.myImage.frame.origin.x, self.myImage.frame.origin.y); 
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, self.myImage.frame.origin.y, 
         endPoint.x, self.myImage.frame.origin.y, endPoint.x, endPoint.y); 
pathAnimation.path = curvedPath; 
CGPathRelease(curvedPath); 

[self.myImage.layer addAnimation:pathAnimation forKey:@"curveAnimation"]; 

MYIMAGE移動到結束好了,但在那之後移動到起點和從起點重複動畫結束。所以,從結束點開始沒有動畫。有可能嗎?

回答

4

動畫回到相同的方式,你來是設置autoreverses爲簡單YES

這就是說,如果它確實是一個無限的動畫,那麼你不需要fillModeremovedOnCompletion

0

我是你,我會簡單地使用:

[UIVIew animateWithDuration:delay:options:animations:completion:]

與選項

UIViewAnimationOptionRepeat