Rotate animation of buttons for IOS-specific pictures

Source: Internet
Author: User

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



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.