我正在对一个从0度摆动到最大200度然后再返回的摆动进行动画处理。问题是,如果钟摆超过180度,它将以最短的路线(沿顺时针方向)返回0。我希望它逆时针旋转。这是我的代码:
('right'是一个 bool 值,当钟摆从左向右摆动时为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谢谢!

麦可

最佳答案

要使其逆时针旋转,只需将x设置为负值(在前面添加-)
你想在哪里

rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(x)];

09-26 09:06