Objective c 用动画顺时针旋转按钮
我正试图顺时针旋转一个按钮,直到用户手动中断它。下面是我用来完成这项任务的代码。我知道它曾经在某个时候起作用。知道怎么修吗?提前谢谢Objective c 用动画顺时针旋转按钮,objective-c,macos,cocoa,nsbutton,Objective C,Macos,Cocoa,Nsbutton,我正试图顺时针旋转一个按钮,直到用户手动中断它。下面是我用来完成这项任务的代码。我知道它曾经在某个时候起作用。知道怎么修吗?提前谢谢 CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; a.fromValue = [NSNumber numberWithFloat:0]; a.toValue = [NSNumber numberWithFloat:-
CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
a.fromValue = [NSNumber numberWithFloat:0];
a.toValue = [NSNumber numberWithFloat:-M_PI*2];
[self.reloadButton.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
a.duration = 2.0; // seconds
a.repeatCount = HUGE_VAL;
[self.reloadButton.layer addAnimation:a forKey:nil];
[第1版]
在看到这是针对NS而不是UI按钮之后,有两个选项:
1为您的OSX版本使用NSTimer和正确的旋转例程,请参见下面的链接
2如果您使用的是OSX 10.5或更高版本,则支持CoreAnimation,并且NSButtons实际上应支持以下内容
维基链接
[原件]
请尝试以下代码:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5000000];
CGAffineTransform rr=CGAffineTransformMakeRotation(5000000);
reloadButton.transform=CGAffineTransformConcat(reloadButton.transform, rr);
[UIView commitAnimations];
下面是一个SO问题的链接,显示了这两种方法
[第1版]
在看到这是针对NS而不是UI按钮之后,有两个选项:
1为您的OSX版本使用NSTimer和正确的旋转例程,请参见下面的链接
2如果您使用的是OSX 10.5或更高版本,则支持CoreAnimation,并且NSButtons实际上应支持以下内容
维基链接
[原件]
请尝试以下代码:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5000000];
CGAffineTransform rr=CGAffineTransformMakeRotation(5000000);
reloadButton.transform=CGAffineTransformConcat(reloadButton.transform, rr);
[UIView commitAnimations];
下面是一个SO问题的链接,显示了这两种方法
只要我设置reloadButton.wantsLayer=YES,您的代码就可以正常工作 从 在iOS应用程序中,核心动画始终处于启用状态,并且每个视图都有一个图层支持。在OS X中,应用程序必须通过执行以下操作明确启用核心动画支持: 链接到QuartzCore框架。iOS应用程序必须链接到 仅当它们使用核心动画界面时,此框架才可用 明确地 为一个或多个NSView对象启用图层支持
只要我设置reloadButton.wantsLayer=YES,您的代码就可以正常工作 从 在iOS应用程序中,核心动画始终处于启用状态,并且每个视图都有一个图层支持。在OS X中,应用程序必须通过执行以下操作明确启用核心动画支持: 链接到QuartzCore框架。iOS应用程序必须链接到 仅当它们使用核心动画界面时,此框架才可用 明确地 为一个或多个NSView对象启用图层支持 试试这个
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(M_PI)];
rotation.duration = 0.2; // Speed
rotation.repeatCount = 1; // Repeat forever. Can be a finite number.
[yourButton.layer addAnimation:rotation forKey:@"Spin"];
[yourButton.layer setZPosition:100];
yourButton.transform = CGAffineTransformMakeRotation(M_PI_2);
您可以根据需要更改/设置持续时间、重复计数和toValue。试试这个
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(M_PI)];
rotation.duration = 0.2; // Speed
rotation.repeatCount = 1; // Repeat forever. Can be a finite number.
[yourButton.layer addAnimation:rotation forKey:@"Spin"];
[yourButton.layer setZPosition:100];
yourButton.transform = CGAffineTransformMakeRotation(M_PI_2);
您可以根据自己的需要更改/设置持续时间、重复计数和toValue。以备将来阅读。本网站是iOS动画版,感谢您的帮助,但上面的代码是针对NSButton而非UIButton。本网站为iOS动画,感谢您的帮助,但上面的代码是针对NSButton而非UIButton。感谢您的帮助,但这实际上是针对mac osx应用程序,即NSButton而非UIButton。感谢您的帮助,但这实际上是针对mac osx应用程序,即NSButton而非UIButton