I am trying to rotate a button using the following method:
-(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)]; }]; }
It is assumed that the button will do some βshaking,β and then it will return to its original position, but all that it does is change the position of the button, move it only to one side and start the method on the other side, which the button does not respond at all.
What is the problem with my code?
Thanks!
EDIT 2: My turn is how can I make a button to shake / sway a bit, for example. wiggle application mode when editing sptingboard.
Using this code gives me a left turn, smooth animates from left to right, then right to left, and then rotates to its original position. Now I want this to not just rotate, but do it with animation, such as 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){ } ];
Thanks!
ios objective-c uibutton
Lior pollak
source share