[英]CAKeyframeAnimation repeat animation from begin to end
我需要從起點到終點以及從終點到起點為UIImageView添加無限動畫。 我正在這樣嘗試:
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從起點移動到結束可以,但是在此之后,移動到起點並從起點到終點重復動畫。 因此,從終點到起點都沒有動畫。 有可能嗎?
以與您過來時相同的方式進行動畫制作,就像將自動autoreverses
設置為YES
一樣簡單。
就是說,如果這確實是一個無限的動畫,那么您就不需要fillMode
或removedOnCompletion
我是你,我只會使用:
[UIVIew animateWithDuration:delay:options:animations:completion:]
與選項
UIViewAnimationOptionRepeat
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.