Picture Move rotation Zoom (transform,center,bounds,frame)

Source: Internet
Author: User
Tags button type

Use of transform in/**ios */
/**transform can change position, size, angle of rotation */
Frame can change position, size (the position and dimensions of the rectangle in which the control resides in the parent control, with the upper-left corner of the parent control as the origin of the coordinates)
Center can change position (the position of the control's midpoint, with the upper-left corner of the parent control as the origin of the coordinates)
Bounds can change dimensions (the position and size of the rectangle where the control is located, with its own upper-left corner as the origin of the coordinates)

iOS7, you can use storyboard, visualize windows, can be pull controls. Storyboard can be implemented, the code must be implemented.
and handwriting code can be achieved, storyboard not necessarily be able to achieve

The following points need to be noted for handwritten code:
1. Use the corresponding control class to create a control object, such as creating a button: UIButton *btn=[[uibutton alloc]init];
2. Need to set various properties of the control, such as location, background map, etc. btn.frame=crrectmake (1,1,100,100);
3. Add the control to the view [Self.view addsubview:btn];
4. Some controls may have a listener event, you also need to consider the event of the control, such as: [Btn addtarget:self Action: @selector (onclick) forControlEvents: UIControlEventTouchUpInside]


#import "SKViewController.h"
Private extension, you can write properties in a. m file
@interface Skviewcontroller ()
@property (nonatomic,weak) iboutlet UIButton *btn;
@end
@implementation Skviewcontroller
-(void) Initialization of the viewdidload//property, code, method, etc.
{

/**
The viewdidload in the parent class will help us do some initialization work, such as a is a base class, b inherits from A, B creates and initializes some members in the Viewdidload method, C Inherits B, If C does not call Super's Viewdidload method when calling Viewdidload, then some members will not be initialized, which may cause problems.
*/
[Super Viewdidload];

UIButton The default type is the rounded Rect button, which is not accepted by the App Store, even if you add a background image to the button, no longer the appearance of the rounded rect, or are rejected by the App Store, In summary, the button type cannot be rounded Rect.
UIButton *head=[uibutton Buttonwithtype:uibuttontypecustom];
The initial position of the picture button is (80,80), both width and height are 80
Head.frame=cgreatmake (80,80,80,80);
To the picture normal state set up a picture named Imagenormal, title text, as well as the title color
[Head.setbackgroundimage=[uiimage imagenamed:@ "Imagenormal"] forstate:uicontrolstatenormal];
[head.settitle:@ "I am the text under normal condition" forstate:uicontrolstatenormal];
[Head.settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];

Set a picture named imagehighlighted, title text, and title color for the picture highlighting state
[Head.setbackgroundimage=[uiimage imagenamed:@ "imagehighlighted"] forstate:uicontrolstatehighlighted];
[head.settitle:@ "I am the text in the highlight state" forstate:uicontrolstatehighlighted];
[Head.settitlecolor:[uicolor Redcolor] forstate:uicontrolstatehighlighted];

Add head to view
[Self.view Addsubview:head];
Self.btn=head;


The Up button
UIButton *upbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Upbtn.frame=cgreatmake (120,120,30,30);
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "Topbtnnormal"] forstate:uicontrolstatenormal];
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "topbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Upbtn settag:1];
[Self.view ADDSUBVIEW:UPBTN];
[Upbtn addtarget:self Action: @selector (onclick) forcontrolevents:uicontroleventtouchupinside]


The Down button
UIButton *downbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Upbtn.frame=cgreatmake (160,120,30,30);
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "Downbtnnormal"] forstate:uicontrolstatenormal];
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "downbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Upbtn Settag:2];
[Self.view ADDSUBVIEW:DOWNBTN];
[Downbtn addtarget:self Action: @selector (onclick) forcontrolevents:uicontroleventtouchupinside]

The left button
UIButton *leftbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Upbtn.frame=cgreatmake (200,120,30,30);
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "Leftbtnnormal"] forstate:uicontrolstatenormal];
[Upbtn.setbackgroundimage:[uiimage imagenamed:@ "leftbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Leftbtn Settag:3];
[Self.view ADDSUBVIEW:LEFTBTN];
[Leftbtn addtarget:self Action: @selector (onclick) forcontrolevents:uicontroleventtouchupinside]

button to the right
UIButton *rightbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Rightbtn.frame=cgreatmake (200,120,30,30);
[Rightbtn.setbackgroundimage:[uiimage imagenamed:@ "Leftbtnnormal"] forstate:uicontrolstatenormal];
[Rightbtn.setbackgroundimage:[uiimage imagenamed:@ "leftbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Rightbtn Settag:4];
[Self.view ADDSUBVIEW:RIGHTBTN];
[Rightbtn addtarget:self Action: @selector (onclick) forcontrolevents:uicontroleventtouchupinside]

Zoomed-in button
UIButton *bigbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Bigbtn.frame=cgreatmake (200,120,30,30);
[Bigbtn.setbackgroundimage:[uiimage imagenamed:@ "Leftbtnnormal"] forstate:uicontrolstatenormal];
[Bigbtn.setbackgroundimage:[uiimage imagenamed:@ "leftbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Bigbtn Settag:5];
[Self.view ADDSUBVIEW:BIGBTN];
[Bigbtn addtarget:self Action: @selector (scale) Forcontrolevents:uicontroleventtouchupinside]

Zoomed-out button
UIButton *smallbtn=[uibutton Buttonwithtype:uibuttontypecustom];
Smallbtn.frame=cgreatmake (200,120,30,30);
[Smallbtn.setbackgroundimage:[uiimage imagenamed:@ "Leftbtnnormal"] forstate:uicontrolstatenormal];
[Smallbtn.setbackgroundimage:[uiimage imagenamed:@ "leftbtnhighlighted"] forstate:uicontrolstatehighlighted];
[Smallbtn Settag:6];
[Self.view ADDSUBVIEW:SMALLBTN];
[Smallbtn addtarget:self Action: @selector (scale) Forcontrolevents:uicontroleventtouchupinside]

-(void) Onclick: (UIButton *) btn
{
Cgpoint Center=self.head.center;
CGRect bounds=self.head.bounds;
Switch (Btn.tag)
{
Case 1:
center.y-=20;
Break
Case 2:
center.y+=20;
Break
Case 3:
center.x-=20;
Break
Case 4:
center.x+=20;
Break
Case 5:
Scale with a center point
bounds.width+=20;
bounds.height+=20;
Break
Case 6:
bounds.width-=20;
bounds.height-=20;
Break
}
Wrap animation effect
Start animation
[UIView Beginanimations:nil Context:nil];
Self.head.center=center;
Set the animation time to 2s
[UIView setanimationduration:2.0];
End Animation
[UIView commitanimation];

}
}


@end

The use of/**transform * *
-(ibaction) Translate
{
On the original basis, the x-axis does not move and the y-axis moves up 100
When moving up, the y axis is negative, when you move to the left, the x axis is negative, the x axis is positive when you move to the right.
Self.view.head.transform=cgaffinetransformtranslate (head.transform,0,-100);
}
-(Ibaction) Rotate
{
The angle is positive, clockwise, or counterclockwise. Angle must be in radians, such as 180-degree camera M_PI
Self.view.head.transform=cgaffinetransformrotate (Head.transform,-m_pi_4);
}
-(ibaction) scale
{
On the original basis, the width and height are 1.5 times times the original, it is the class on the
Self.view.head.transform=cgaffinetransformscale (head.transform,1.5,1.5);
}

Picture Move rotation Zoom (transform,center,bounds,frame)

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.