我正在尝试制作一个有点像速度计的动画。
第一个动画得到了针
CFTimeInterval localMediaTime = [needle convertTime:CACurrentMediaTime() fromLayer:nil];
CABasicAnimation *needAni = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
needAni.duration = 0.5f;
needAni.fromValue = [NSNumber numberWithFloat:0.0];
needAni.toValue = [NSNumber numberWithFloat:(rotVal * M_PI / 180.0)];
needAni.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.195: 0.600: 0.790: 0.405];
needAni.fillMode = kCAFillModeBackwards;
[needle.layer addAnimation:needAni forKey:nil];
在那之后,我想让针在达到全速时来回弹跳一点。这个动画就是这样做的:
CABasicAnimation *needAni2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
needAni2.duration = 0.1f;
needAni2.fromValue = [NSNumber numberWithFloat:(rotVal * M_PI / 180.0)];
needAni2.toValue = [NSNumber numberWithFloat:((rotVal+5) * M_PI / 180.0)];
needAni2.fillMode = kCAFillModeBackwards;
needAni2.autoreverses = YES;
needAni2.repeatCount = HUGE_VAL;
needAni2.beginTime = localMediaTime + 0.5f;
[needle.layer addAnimation:needAni2 forKey:nil];
现在,当我把它放在一起时,只会播放第二个动画。
我厌倦了将这两个动画放在一个组中,但我似乎不能只重复第二个动画,它会重复整个过程。如果我将组持续时间设置为 HUGE_VAL 是否存在性能问题,或者是否有更好的方法来做到这一点?
谢谢