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 に答える