我正在制作一个钟摆的动画,该钟摆从 0 度摆动到最大 200 度,然后再返回。问题是,如果摆超过 180 度,它会通过最短路线返回到 0 度,即继续顺时针旋转。我希望它逆时针旋转。这是我的代码:
(“right”是一个布尔值,当钟摆从左向右摆动时,该值为 TRUE)
- (void)swingPendulum {
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
if (right)
rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(kMax)];
else
rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(kMin)];
rotationAnimation.duration = 1.0;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.delegate = self;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
rotationAnimation.removedOnCompletion = NO;
[pendulum.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
我有什么想法可以让这项工作成功吗?这是我的挥杆计拼图的最后一块,否则效果很好:D 谢谢!
Michael
要使其逆时针旋转,只需设置x
为负值(在前面加 -)
你想在哪里
rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(x)];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)