Use button to move, scale, rotate, reset and so on.

Source: Internet
Author: User
Tags uikit

In UIView there is a view called button, the control is simply a click, that is, all of the things we can click on the Phone are button, now we use this control to achieve the above and so on.

PS: Methods and comments are all in the file project, you can download it and run it, and here I just write the code.

about how to use UIButton, you can go to Baidu, there is a special video explanation, here the map is more troublesome, bad operation, please understand.

ViewController.h declares all the methods.

#import<UIKit/UIKit.h>@interfaceViewcontroller:uiviewcontroller//declares the attributes of the UIButton being controlled.@property (Weak, nonatomic) Iboutlet UIButton *btn;//declares the Move method up or down.-(Ibaction) button: (ID) sender;//declares the scaling method.-(Ibaction) Scale: (ID) sender;//declares the method of rotation.-(ibaction) Rotate: (ID) sender;//initializes the button.-(Ibaction) Initialize: (ID) sender;@end

VIEWCONTROLLER.M file to implement all the methods.

#import "ViewController.h"//You can also create a macro that is more convenient and does not waste memory space.#defineKdelta 10@interfaceViewcontroller ()@end@implementationViewcontroller- (void) Btncilickwithblock: (void(^) ()) block{//animation ready to start[UIView Beginanimations:nil Context:nil]; //time the animation ran[UIView setanimationduration:1.0f]; //implementation method.block (); //run the animation.[UIView commitanimations];}#pragmaMark control button move around (up and down)-(ibaction) Buttons: (ID) sender{[self btncilickwithblock:^{        //in addition to using frame, you can also use the centerCGRect frame =_btn.frame;//cgpoint tmpcenter = _btn.center; //Why use CGFloat, because Origin is inherited and CGRect, CGRect is a floating-point type, so use CGFloat. //CGFloat Dale = 50; //You can use the switch method, or you can use the If judgment method, as you like. //because sender is an ID type, you cannot use the. operator, so you can only use the Get method.        Switch([sender tag]) { Case 1: Frame.origin.y-=Kdelta; if(FRAME.ORIGIN.Y <=Ten) {FRAME.ORIGIN.Y=0; }//tmpcenter.y-= Kdelta;                 Break;  Case 2: frame.origin.x+=Kdelta; if(Frame.origin.x >= About) {frame.origin.x= -; }//tmpcenter.x + = Kdelta;                 Break;  Case 3: Frame.origin.y+=Kdelta; if(FRAME.ORIGIN.Y >=458) {FRAME.ORIGIN.Y=468; }//tmpcenter.y + = Kdelta;                 Break;  Case 4: frame.origin.x-=Kdelta; if(Frame.origin.x <=Ten) {frame.origin.x=0; }//tmpcenter.x-= Kdelta;                 Break; default:                 Break; } _btn.frame=frame;//_btn.center = tmpcenter;    }];}#pragmaMark Spin-(ibaction) Rotate: (ID) Sender {//radians 3.14-π//Angle//here the system has defined a macro for us. //rotate counterclockwise to precede the macro with the-operator, otherwise it is the + operator. //the m_pi_4 here means to rotate 45°. //_btn.transform = cgaffinetransformmakerotation (-m_pi_4);[Self btncilickwithblock:^{        if(5==[sender tag]) {_btn.transform= Cgaffinetransformrotate (_btn.transform, M_pi_2 *-1); }        Else if(6==[sender tag]) {_btn.transform= Cgaffinetransformrotate (_btn.transform, M_pi_2 *1); }    }];}#pragmaMark Zoom-(ibaction) Scale: (ID) sender{[self btncilickwithblock:^{        //use the three-mesh operator to determine which button is.CGFloat scale = [Sender tag] = =7?1.2:0.8; //determines the button label.        if([sender tag] = =7) {_btn.transform=Cgaffinetransformscale (_btn.transform, scale, scale); }        Else if([sender tag] = =8) {_btn.transform=Cgaffinetransformscale (_btn.transform, scale, scale); }    }];}#pragmaMark Initialization-(ibaction) Initialize: (IDsender {[Self btncilickwithblock:^{        //initializes all the deformation properties before initializing._btn.transform =cgaffinetransformidentity; }];}@end

Engineering:

Http://files.cnblogs.com/iOSCain/%E6%8C%89%E9%92%AE%E7%9A%84%E7%8A%B6%E6%80%81.zip

Use button to move, scale, rotate, reset and so on.

Related Article

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.