gpt4 book ai didi

ios - 在 CABasicAnimation 中改变 CALayer 的速度,同时旋转一个轮子会导致 jerk 效果

转载 作者:可可西里 更新时间:2023-11-01 04:21:22 25 4
gpt4 key购买 nike

我开发了一个应用程序,它需要一个轮子绕 z 轴旋转,随着时间的推移稳定地增加或减少轮子的速度。我使用 CABasicAnimation & 我的代码如下。当我以特定间隔更改图层的速度属性时,它会对车轮产生“急动”效果。

/****/

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.toValue = [NSNumber numberWithFloat:-2*M_PI];
animation.duration = 4.0f;
animation.repeatCount = INFINITY;
[animation setValue:@"left" forKey:@"side"];
[animation setDelegate:self];
animation.removedOnCompletion=NO;
animation.fillMode = kCAFillModeForwards;
animation.cumulative = YES;

imageLeft.layer.beginTime = CACurrentMediaTime();
/************/

在计时器中,我按如下方式改变 ImageView 的 CALayer 的速度,其中 dPlayedPercentage 是一个变量。

imageLeft.layer.speed=1.0+dPlayedPercentage;

[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];

我认为这是由于在更改 CALayer 的速度属性时位置重置所致。我应该怎么做才能纠正这个问题。或任何其他方式来制作此动画?

最佳答案

添加以下代码已纠正动画中的抖动。

imageLeft.layer.timeOffset = [imageLeft.layer convertTime:CACurrentMediaTime() fromLayer:nil]; 
imageLeft.layer.beginTime = CACurrentMediaTime();
imageLeft.layer.speed=1.0+dPlayedPercentage;

关于ios - 在 CABasicAnimation 中改变 CALayer 的速度,同时旋转一个轮子会导致 jerk 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17276628/

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