我似乎无法获得一个简单的 3d 转换来处理按钮,并且文档似乎没有帮助。我从一个基于视图的应用程序模板开始。我添加了 QuartzCore 框架并将其导入到 ViewController 标头中。在界面生成器中,我拖出两个圆形矩形按钮并将它们分别连接到 button1 和 button2,并将它们都连接到 buttonPressed: 方法。
注释掉动画的快速运行验证只有单击的按钮会更改其标签。
回到动画后,“sender.transform = t;”上的“setTransform:”参数 1 出现错误类型不兼容 行(现在固定行更改为 [sender.layer setTransform:t];)
如何让它旋转 360 度。我认为问题在于开始和结束状态是相同的,所以它不知道在任何地方旋转。
这是.h,(出于格式原因,我在这篇文章中省略了导入)
@interface animation2ViewController : UIViewController {
IBOutlet UIButton *button1;
IBOutlet UIButton *button2;
}
-(IBAction) buttonPressed:(UIButton *)sender;
@end
和 .m 文件
#import "animation2ViewController.h"
@implementation animation2ViewController
-(IBAction)buttonPressed:(UIButton *)sender {
[sender setTitle:@"new title" forState:UIControlStateNormal];
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationCurveEaseInOut
animations:^{
CATransform3D t = CATransform3DIdentity;
t.m34 = -1 / 1000;
t = CATransform3DRotate(t, 360 * M_PI / 180, 0.0, 1.0, 0.0); //ultimately want 360 degrees but starting here first
[sender.layer setTransform:t];
}
completion:^(BOOL finished) {
}];
}