旋转 NSButton 不起作用

Rotating an NSButton not working

我有对角向下动画的代码。

CABasicAnimation *rightAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
[rightAnimation setToValue:[NSNumber numberWithFloat:160]];
[rightAnimation setBeginTime:0.0];
[rightAnimation setDuration:0.4];


CABasicAnimation *fall = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
[fall setToValue:[NSNumber numberWithFloat:-20]];
[fall setBeginTime:0.1];
[fall setDuration:0.3];

//DOESN'T WORK
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.translation.z"];
[rotate setToValue:[NSNumber numberWithFloat:DEGREES_RADIANS(30)]];
[rotate setBeginTime:0.0];
[rotate setDuration:0.4];

CAAnimationGroup *group = [CAAnimationGroup animation];
[group setDuration:0.4];
[group setAnimations:[NSArray arrayWithObjects:rightAnimation, fall, rotate, nil]];

[submitButton.layer addAnimation:rotate forKey:nil];

除了我还想让按钮旋转 30 度外,它工作得很好。但是由于一些奇怪的原因,这并没有发生,怎么会呢?

我没见过"DEGREES_RADIANS,"我相信你的意思可能是"degreesToRadians."如果是这样,下面的代码就足够了:

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

更改此行:

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.translation.z"];

对此:

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

这应该可以解决您的问题。