我正在尝试使用 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"];