旋转UIButton

Lio*_*lak 3 objective-c uibutton ios

我一直在尝试使用以下方法旋转按钮:

-(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)];
    }];
}
Run Code Online (Sandbox Code Playgroud)

这应该使按钮做某种"摇动",然后它应该回到原来的位置 - 但它所做的只是改变按钮的位置,将它移动到只有一侧,并在另一个方法的运行中按钮没有反应在所有.

我的代码有什么问题?

谢谢!

编辑2:我的问题是 - 我如何制作一个按钮来做一些摇摆/摆动,例如编辑sptingboard时的摆动应用模式.

使用此代码可以让我向左旋转,从左到右,然后从右到左平滑动画,然后旋转到原始位置.现在,我希望这不仅仅是旋转,而是通过动画来实现,就像摆动一样.

[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){
                 }
 ];
Run Code Online (Sandbox Code Playgroud)

谢谢!

Sha*_*dul 6

导入"QuartzCore/QuartzCore.h"并尝试这个,

CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.delegate = self;
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 1.7;
fullRotation.repeatCount = 2;
[btnTemp.layer addAnimation:fullRotation forKey:@"360"];
Run Code Online (Sandbox Code Playgroud)