旋转 NSButton 不起作用
Posted
技术标签:
【中文标题】旋转 NSButton 不起作用【英文标题】:Rotating an NSButton not working 【发布时间】:2017-02-03 17:35:40 【问题描述】:我有对角向下动画的代码。
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 度之外,它可以完美地工作。但是由于某种奇怪的原因,这并没有发生,怎么会呢?
【问题讨论】:
【参考方案1】:改变这一行:
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.translation.z"];
到这里:
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
这应该可以解决您的问题。
【讨论】:
【参考方案2】:我从未见过“DEGREES_RADIANS”,我相信您实际上可能指的是“degreesToRadians”。如果是这样,下面的代码就足够了:
rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(30)];
【讨论】:
以上是关于旋转 NSButton 不起作用的主要内容,如果未能解决你的问题,请参考以下文章