Rotation animation of buttons for iOS-specific images
To add a rotation animation for a button with a specific image, 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: @ "Rotate" 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. transform = CGAffineTransformMakeRotation (M_PI);} completion: ^ (BOOL finished) {flag = NO ;}];} else {[UIView animateWithDuration: 0.5 animations: ^ {_ imageView. transform = CGAffineTransformMakeRotation (0);} completion: ^ (BOOL finished) {flag = YES ;}] ;}@ end
During running, the orientation of the real machine device and the simulator button rotation animation may be a bit different, a little strange.
Some of them run as follows:
Demo address: Click to open the link