Rotation animation of buttons for iOS-specific images

Source: Internet
Author: User

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.