Ios_2_ Button Controls Object deformation

Source: Internet
Author: User

BeyondViewController.h

  beyondviewcontroller.h//  02_ Button control object deformation////  Created by Beyond on 14-7-21.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller// Controller members Remember that the Avatar button on the interface @property (weak, nonatomic) Iboutlet UIButton *headbtn;//button controls the head button move up or down-(ibaction) Btnclick: ( UIButton *) sender;-(ibaction) AffineTransform: (UIButton *) sender;-(ibaction) Reset: (UIButton *) sender; @end



Beyondviewcontroller.m

beyondviewcontroller.m//02_ Button Controls object deformation////Created by Beyond on 14-7-21.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" #define KDELTA 20const int DELTA = @interface        Beyondviewcontroller () {///left rotation the dumbest method member variable Remember radians can accumulate cgfloat _angel; The member remembers headbtn default frame CGRect _headbtnframe;}    @end @implementation beyondviewcontroller-(void) viewdidload{[Super Viewdidload];        The view load is used to remember the initial position of the HEADBTN with the member _headbtnframe = _headbtn.frame;    Calling a custom method, the code creates Buttuon [self addbuttionbycoding]; [Self addtextfieldbycoding];} # pragma mark-button control Head button moves up and down-(void) Movebyframe: (UIButton *) sender{//UIView class method for animating (starting animation) [Uivie    W Beginanimations:nil Context:nil];            The default animation duration is 0.2 [UIView setanimationduration:1];    The following three steps are the OC Standard Code, because OC does not allow the value of the member of the struct attribute in the object to be repaired directly, through the intermediate temporary structure body variable cgrect frame = Self.headBtn.frame; The general number is the same words can be extracted as: 1, variable; 2, Macro;    3,const int//CGFloat delta = 50; #define KDelta//const int delta = 50;    int tag = [sender tag];            Switch (TAG) {case 1:FRAME.ORIGIN.Y-= Kdelta;        Break            Case 2:frame.origin.x + = Kdelta;        Break            Case 3:FRAME.ORIGIN.Y + = Kdelta;        Break            Case 4:frame.origin.x-= Kdelta;                    Break    Default:break;                } self.headbtn.frame=frame; UIView class method for animating (ending animation) [UIView commitanimations];} -(Ibaction) Btnclick: (UIButton *) sender {[Self animatewithblock:^{//The following three steps are OC Standard Code, because the OC does not allow straight        The value of the member of the struct attribute in the object is repaired by Cgpoint Center = Self.headBtn.center through the intermediate temporary structure body variable; The general number is the same words can be extracted as: 1, variable; 2, Macro;        3,const int//CGFloat delta = 50;                                #define KDELTA/const int DELTA = 50;        int tag = [sender tag]; Switch (TAG) {case 1:CENTER.Y-= KdeltA            Break                Case 2:center.x + = Kdelta;            Break                Case 3:center.y + = Kdelta;            Break                Case 4:center.x-= Kdelta;                            Break        Default:break;            } self.headBtn.center = center;    }]; } #pragma mark-button control Head button left/right rotation zoom out-(ibaction) AffineTransform: (UIButton *) Sender {//UIView class method for animating effect (start    Animation) [UIView Beginanimations:nil Context:nil];    The default animation duration is 0.2 [UIView setanimationduration:1];    int tag = [sender tag];            Switch (TAG) {case one://_angel-= M_pi_4;                        Rotation clockwise to the positive direction, using radians m_pi_4 is clockwise rotation 45 degrees//_headbtn.transform = cgaffinetransformmakerotation (_angel); Cgaffinetransformrotate method: Returns a new struct, a new structure with a certain radian rotation on the basis of the original structure _headbtn.transform = Cgaffinetr Ansformrotate (_headbtn.transform,- M_pi_4);        Break            Case://_angel + = M_pi_4;                        Rotation clockwise to the positive direction, using radians m_pi_4 is clockwise rotation 45 degrees//_headbtn.transform = cgaffinetransformmakerotation (_angel); Cgaffinetransformrotate method: Returns a new struct, a new structure with a certain radian rotation on the basis of the original structure _headbtn.transform = Cgaffinetr            Ansformrotate (_headbtn.transform, m_pi_4);        Break            Case 13://shrink//_headbtn.transform = Cgaffinetransformmakescale (0.5, 0.5);            _headbtn.transform = Cgaffinetransformscale (_headbtn.transform, 0.8, 0.8);        Break            Case 14://magnification//_headbtn.transform = Cgaffinetransformmakescale (1.5, 1.5);            _headbtn.transform = Cgaffinetransformscale (_headbtn.transform, 1.2, 1.2);        Break            Case 0://Click Headbtn, Empty and revert to the default state _headbtn.transform = cgaffinetransformidentity;            _headbtn.frame = _headbtnframe;        Break Default            Break }//UIView class method for animating (ending animation) [UIView commitanimations];} #pragma mark-through block encapsulation code//Void (^myblock) (), Void (^myblock) () = ^{NSLog (@ "beyond");};/ /manual block () a bit of a problem-(void) Animatewithblock: (void (^) ()) block{//UIView class method for animating (start animation) [UIView Beginanimations:nil    Context:nil];        The default animation duration is 0.2 [UIView setanimationduration:1];        Block (); UIView class method for animating (ending animation) [UIView commitanimations];}  -(ibaction) Reset: (UIButton *) sender {[Self animatewithblock:^{//click, empty and revert to default state _headbtn.transform =        cgaffinetransformidentity;    _headbtn.frame = _headbtnframe; }];}    -(void) addbuttionbycoding{//1, create a button instance with the class method UIButton *button = [[UIButton alloc] init];        2, set button details Button.frame = CGRectMake (0, 0, 100, 100);    normal state [button settitle:@ "normal" forstate:uicontrolstatenormal];    [Button Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal]; [Button Setimage:[uiimageimagenamed:@ "Btn_01.png"] forstate:uicontrolstatenormal];    [Button setbackgroundimage:[uiimage imagenamed:@ "Btn_01.png"] forstate:uicontrolstatenormal];    Highlight status when Clicked [Button settitle:@ "highlighted" forstate:uicontrolstatehighlighted];    [Button Settitlecolor:[uicolor Bluecolor] forstate:uicontrolstatenormal];    [Button setimage:[uiimage imagenamed:@ "Btn_02.png"] forstate:uicontrolstatehighlighted];    [Button setbackgroundimage:[uiimage imagenamed:@ "Btn_02.png"] forstate:uicontrolstatehighlighted];    Add a Click event to the button [button addtarget:self action: @selector (Codebtnclick:) forcontrolevents:uicontroleventtouchupinside]; 3, add the button to the current controller's view inside [Self.view Addsubview:button];}    The code creates the button's Click event-(void) Codebtnclick: (UIButton *) sender{NSLog (@ "%@", sender); NSLog (@ "%p", sender);}    Code creation text input box-(void) addtextfieldbycoding{//1, class method creation control Uitextfield *textfield = [[Uitextfield alloc]init];    2, control details Textfield.frame = CGRectMake (100, 0, 100, 100); Textfield.backGroundcolor = [Uicolor Graycolor];    System font Size Textfield.font = [Uifont systemfontofsize:20];    Textfield.font = [Uifont boldsystemfontofsize:30];    Center display cgfloat x = self.view.frame.size.width*0.5;    CGFloat y = self.view.frame.size.height*0.5;    Textfield.center = Cgpointmake (x, y);    The following three steps are the OC Standard code, since OC does not allow the value of the member of the struct attribute in the object to be repaired directly, through the intermediate temporary structure body variable Cgpoint center = textfield.center;    center.x = x;    Center.y = y;        Textfield.center = center; 3, add the control to the current controller's view [Self.view Addsubview:textfield];} @end


















Ios_2_ Button Controls Object deformation

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.