In recent things, to add a rotation animation to a button with a specific picture, the demo code is as follows:
#import "ViewController.h" @interface Viewcontroller () {BOOL flag;} @property (Strong, nonatomic) Uiimageview *imageview; @end @implementation Viewcontroller-(void) Viewdidload { [Super Viewdidload]; flag = YES; Self.imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 35, 35)]; UIImage *aimage = [UIImage imagenamed:@ "Down.png"]; [_imageview Setimage:aimage]; _imageview.center = Self.view.center; [Self.view Addsubview:_imageview]; UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem]; [Button settitle:@ "rotation" forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (rotate:) forcontrolevents:uicontroleventtouchupinside]; Button.frame = CGRectMake (110, 400, 100, 44); [Self.view Addsubview:button];} -(void) rotate: (ID) Sender {if (flag) {[UIView animatewithduration:0.5 animations:^{_imageview.tran Sform = Cgaffinetransformmakerotation (M_PI); } completion:^ (BOOL finished) {flag = NO; }]; } else {[UIView animatewithduration:0.5 animations:^{_imageview.transform = Cgaffinetransformmakero tation (0); } completion:^ (BOOL finished) {flag = YES; }]; }} @end
In the run-time real machine device and the emulator's button rotation animation, the direction may be a little different, a bit strange.
Some of them run as follows:
Demo Address: Click to open the link