1

我正在尝试使用 CABasicAnimation 创建一个简单的动画,该动画将始终保持恒定速度,即使动画必须行进的距离永远不会相同。到目前为止,这是我的代码,它正在滚动一个大小总是不同的标签,但还不能保持恒定的速度。非常感谢您的帮助。

CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.speed = 1.0f;

NSNumber *fromValue = [NSNumber numberWithFloat:self.mainLabel.frame.origin.x];
NSNumber *toValue = [NSNumber numberWithFloat:-self.mainLabel.frame.size.width - self.view.frame.size.height];
theAnimation.fromValue = fromValue;
theAnimation.toValue = toValue;
//theAnimation.duration = toValue.floatValue - fromValue.floatValue;//Not right.
theAnimation.repeatCount = 999;
theAnimation.autoreverses = NO;
[mainLabel.layer addAnimation:theAnimation forKey:@"animateLayer"];
4

1 回答 1

1

您是否尝试添加:

 theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

例如之后

 theAnimation.speed = 1.0f;   

?

此功能设置动画的线性速度。

于 2012-08-16T06:45:51.347 回答