具有相同速度的 CAAnimation 对象的不同距离?
我有多个对象可以在不同距离的路径上移动。如何使所有物体的速度相同?
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"]; 路径动画.速度 = 0.5;
不起作用;(
如果距离更大,速度会增加。
I have mutiple objects to move on paths with different distance. How can I get the same speed of all objects?
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.speed = 0.5;
Doesn't work ;(
If the distance is bigger the speed increases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有测试过这个想法,但是,速度似乎被定义为相对值。
如果可以计算路径长度,则可以将其重新计算为像素相对值。动画的速度将为
animation.speed = baseSpeedInPixels / thisPathLengthInPixels;
,其中baseSpeedInPixels是所需的基本速度常量。它可能会导致值大于 1.0,如果动画类不理解这一点,您可以重新映射计时值以将速度保持在 [0,1] 范围内。
I haven't tested this idea, however, it seems like the speed is defined as relative value.
You can re-compute it into the pixel-relative value if you can compute the paths length. The speed of the animation will be
animation.speed = baseSpeedInPixels / thisPathLengthInPixels;
where baseSpeedInPixels is the desired base speed constant.It might result values bigger than 1.0, if the animation class doesn't understand this, you can re-map the timing values to keep the speed in [0,1] range.