gpt4 book ai didi

ios - CAKeyframeAnimation 从头到尾重复动画

转载 作者:行者123 更新时间:2023-11-28 19:08:46 27 4
gpt4 key购买 nike

我需要为 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 一样简单。

也就是说,如果它真的是一个无限动画,那么您就不需要 fillModeremovedOnCompletion

关于ios - CAKeyframeAnimation 从头到尾重复动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17717929/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com