"iOS Development-43" Universal transform considerations, as well as some knowledge of viewwithtag and. PNG suffixes can be omitted

Source: Internet
Author: User

Precautions:


(1) If the image is in PNG format, you can omit the suffix in the code.


(2) You can give the control a tag value, and then use Viewwithtag to get the control.


(3) The upper and lower left and right movement of the transform is in accordance with the vertical direction of its upper and lower border movement, that is, if you rotate the control, then the upper and lower left and right is not the traditional up and down, but oblique up and down around.


(4) The transform can achieve the effect of rotating and zooming around, but it is relative to a position, if the relative position is unchanged, it is equivalent to only one time, and if each time the changed position is reset to a new relative position, it will take effect each time. That is, in code, there are two ways.


#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) Viewdidload {//    Create a btn, inside the image UIButton *btnimg=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnimg.frame=cgrectmake (130, 120, 100, 100);    If it is a. png image, you can omit the. png suffix [btnimg setbackgroundimage:[uiimage imagenamed:@ "HI"] forstate:uicontrolstatenormal];    Add a tag for subsequent acquisition of this btnimg btnimg.tag=1;        [Self.view addsubview:btnimg];    Create up and down, rotate around, zoom out button UIButton *btnup=[uibutton buttonwithtype:uibuttontyperoundedrect];    Btnup.frame=cgrectmake (80, 400, 20, 20);    [Btnup settitle:@ "on" forstate:uicontrolstatenormal];    [Btnup addtarget:self Action: @selector (UP) forcontrolevents:uicontroleventtouchupinside];        [Self.view Addsubview:btnup];    UIButton *btndown=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btndown.frame=cgrectmake (80, 460, 20, 20);    [Btndown settitle:@ "under" forstate:uicontrolstatenormal]; [Btndown addtarget:self Action: @selector (down) forControlevents:uicontroleventtouchupinside];        [Self.view Addsubview:btndown];    UIButton *btnleft=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnleft.frame=cgrectmake (50, 430, 20, 20);    [Btnleft settitle:@ "left" forstate:uicontrolstatenormal];    [Btnleft addtarget:self Action: @selector (left) forcontrolevents:uicontroleventtouchupinside];        [Self.view Addsubview:btnleft];    UIButton *btnright=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnright.frame=cgrectmake (110, 430, 20, 20);    [Btnright settitle:@ "right" forstate:uicontrolstatenormal];    [Btnright addtarget:self Action: @selector (right) forcontrolevents:uicontroleventtouchupinside];        [Self.view Addsubview:btnright];    UIButton *btnroleft=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnroleft.frame=cgrectmake (150, 430, 40, 20);    [Btnroleft settitle:@ "left" forstate:uicontrolstatenormal];  [Btnroleft addtarget:self Action: @selector (Roleft) forcontrolevents:uicontroleventtouchupinside];  [Self.view Addsubview:btnroleft];    UIButton *btnroright=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnroright.frame=cgrectmake (200, 430, 40, 20);    [Btnroright settitle:@ "Turn right" forstate:uicontrolstatenormal];    [Btnroright addtarget:self Action: @selector (Roright) forcontrolevents:uicontroleventtouchupinside];        [Self.view Addsubview:btnroright];    UIButton *btnbig=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnbig.frame=cgrectmake (250, 430, 40, 20);    [Btnbig settitle:@ "amplification" forstate:uicontrolstatenormal];    [Btnbig addtarget:self Action: @selector (BIG) forcontrolevents:uicontroleventtouchupinside];        [Self.view Addsubview:btnbig];    UIButton *btnsmall=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btnsmall.frame=cgrectmake (300, 430, 40, 20);    [Btnsmall settitle:@ "Zoom Out" forstate:uicontrolstatenormal];    [Btnsmall addtarget:self Action: @selector (small) forcontrolevents:uicontroleventtouchupinside];     [Self.view Addsubview:btnsmall];   [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.} There is only one button, there is no need to pass this button parameter come over-(void) up{////////Viewwithtag Get the UIView object, if we know what kind of uiview, you can cast UIButton *btnimg1= (    UIButton *) [Self.view viewwithtag:1]; The following statement moves up 10, but the button only takes effect once, because it is equivalent to the assignment ty=-10, and it moves only relative to the original position, so the original position is unchanged, and the ty=-10 does not change, and the value of Ty is no longer moved//each time the button is clicked,    either by changing its relative position, that is, setting the newest position to its relative position//btnimg1.transform=cgaffinetransformmaketranslation (0,-10); Btnimg1.transform=cgaffinetransformtranslate (btnimg1.transform, 0,-10);}    -(void) down{//Similarly, the following UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1]; Btnimg1.transform=cgaffinetransformtranslate (btnimg1.transform, 0, 10);}    -(void) left{//Similarly, the following UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1]; Btnimg1.transform=cgaffinetransformtranslate (Btnimg1.transform,-10, 0);}    -(void) right{//Similarly, the following UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1]; Btnimg1.transform=cgaffinetransformtranslate (Btnimg1.transform, 10, 0);}    -(void) roleft{UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1];    Similarly, the first sentence can only be clicked effective 1 times, and with a radian system of numbers, Pi/4//btnimg1.transform=cgaffinetransformmakerotation (-m_pi_4); Btnimg1.transform=cgaffinetransformrotate (Btnimg1.transform,-m_pi_4);}    -(void) roright{//Empathy UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1]; Btnimg1.transform=cgaffinetransformrotate (Btnimg1.transform, m_pi_4);}    -(void) big{UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1];    Similarly, the first sentence can only be clicked effective 1 times, and with a radian system of numbers, Pi/4//btnimg1.transform=cgaffinetransformmakescale (1.2, 1.2); Btnimg1.transform=cgaffinetransformscale (Btnimg1.transform, 1.2, 1.2);}    -(void) small{//Empathy UIButton *btnimg1= (UIButton *) [Self.view viewwithtag:1]; Btnimg1.transform=cgaffinetransformscale (Btnimg1.transform, 0.8, 0.8);} @end

Results:


"iOS Development-43" Universal transform considerations, as well as some knowledge of viewwithtag and. PNG suffixes can be omitted

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.