旋转NSButton不起作用

时间:2017-02-03 17:35:41

标签: objective-c macos cocoa caanimation

我有对角线下来动画的代码。

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度。但是出于一些奇怪的原因,这不会发生,为什么会这样呢?

2 个答案:

答案 0 :(得分:1)

更改此行:

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

到此:

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

那应该解决你的问题。

答案 1 :(得分:0)

我从未见过“DEGREES_RADIANS”,我相信你实际上可能意味着“度达到拉丁语”。如果是这样,以下代码就足够了:

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