【发布时间】:2013-04-25 16:56:14
【问题描述】:
我一直在尝试使用以下方法旋转按钮:
-(IBAction)rotate:(id)sender{
CGPoint pencilCenter = pencil.center;
[pencil setCenter:pencilCenter];
CGFloat floater = 1.0;
[UIView animateWithDuration:0.7 animations:^(void){
[pencil setTransform:CGAffineTransformMakeRotation(floater)];
}];
[UIView animateWithDuration:0.7 animations:^(void){
[pencil setTransform:CGAffineTransformMakeRotation(floater)];
}];
}
这应该使按钮进行某种“摇动”,然后它应该回到原来的位置 - 但它所做的只是改变按钮的位置,将其仅移动到一侧并在另一次运行按钮没有反应的方法根本。
我的代码有什么问题?
谢谢!
编辑 2: 我的问题是 - 我如何制作一个按钮来做一点摇晃/摆动,例如编辑 sptingboard 时的 Wiggle 应用模式。
使用此代码让我向左旋转,从左到右然后从右到左平滑动画,然后旋转到原始位置。现在,我希望它不仅仅是旋转,而是通过动画来实现,比如摆动。
[UIView animateWithDuration:0.25
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse)
animations:^ {
pencil.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(30));
pencil.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished){
}
];
谢谢!
【问题讨论】:
-
为什么要同时启动 2 个旋转量相同的动画?
-
请明确“将其移至一侧”的确切含义。也许贴一些模拟器的截图?
-
您可以尝试以下帖子,它适用于 UIView 但您可以将其应用于 UIButton stackoverflow.com/questions/929364/…
-
我再次阅读了 CoreAnimation 文档,问题是(几乎可以肯定)锚点...
标签: ios objective-c uibutton