First, UIView Common Properties (1) @property (nonatomic,readonly) UIView *superview; Gets its own parent control object (2) @property (nonatomic,readonly,copy) UIView *subviews;//gets all of its child control objects (3) @property (nonatomic) The ID of the Nsinteger tag;//control is identified, and the parent control can find the corresponding child control through the tag, which defaults to 0 (4) @property (nonatomic) CGRect the position and size of the rectangle where the frame;//control is located ( With the upper-left corner of the parent control as the coordinate origin) (5) @property (nonatomic) CGRect the position and dimensions of the rectangle where the bounds;//control is located (the origin of the coordinates in its upper-left corner,with Bounds's x\y forever is 0)(6) position of the midpoint of the @property (nonatomic) Cgpoint center;//control (in the upper-left corner of the parent control as the origin point of the coordinates) (7) @property (nonatomic) Cgaffinetransform transform ;//deform Properties of the control (you can set the rotation angle, scale, pan, and so on)A. Rotation: Cgaffinetransform Cgaffinetransformscale (Cgaffinetransform T, cgfloat SX, CGFloat sy) SX and Sy are the coordinates of the scaling factor B. Retraction: Cgaffinetransform cgaffinetransformrotate (cgaffinetransform t,cgfloat angle) angle: Rotation degree C. Inversion: Cgaffinetransform Cgaffinetransforminvert (Cgaffinetransform t) d. Two matrix affine for a new matrix:CgaffinetransformCgaffinetransformconcat (cgaffinetransform t1,cgaffinetransform T2) E. Determine if two matrices are equal: bool Cgaffinetransformequaltotransform (cgaffinetransform t1, Cgaffinetransform T2)
Create an affine matrix
- Cgaffinetransformmake Direct assignment to create
- Cgaffinetransformmakerotation setting the angle to generate the matrix
- The result is
- Cgaffinetransformmakescale set the zoom, and change the value of a, D
- Cgaffinetransformmaketranslation Setting the Offset
Change the existing radiation matrix
- Cgaffinetransformtranslate the original base plus the offset
- Cgaffinetransformscale Plus Zoom
- Cgaffinetransformrotate Plus rotation
- Cgaffinetransforminvert inverse affine matrices such as (x, y) are obtained through the matrix T, then the T ' effect generated by this function and (x ', y ') can be obtained from the original
- Cgaffinetransformconcat generates a new matrix with two existing radiation matrices t ' = T1 * T2
Applying affine matrices
- Cgpointapplyaffinetransform get a new point
- Cgsizeapplyaffinetransform get a new size
- Cgrectapplyaffinetransform get a new rect
Component diagram frame for view views frame is of type CGRect structure bodystruct CGRect{Cgpoint origin;cgsize size;};struct Cgponit{cgfloat x;cgfloat y;};struct Cgsize{cgfloat width;cgfloat height;};
Component deformation control for view views the type of transform is the cgaffinetransform structure, which is a matrix (which can be scaled, panned, rotated, etc.)
struct Cgaffinetransform {
CGFloat A, B, C, D;
CGFloat tx, Ty;
};
Ii. Initialization of UIButton – the most common initialization method
UIButton *btn = [[UIButton alloc] initwithframe:rect];
– Fast Initialization
UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];
The –type parameter is used to specify the type of button, a total of 6 options: uibuttontypecustom: No type, the content of the button needs to be customized uibuttontyperoundedrect: round rectangular Border · Uibuttontypedetaildisclosure: uibuttontypeinfolight: uibuttontypeinfodark: Uibuttontypecontactadd:
Works: Boxman
1 #import "ViewController.h"2typedefenum3 {4buttontypeleft=1,5 Buttontyperight,6 Buttontypeup,7 Buttontypedown,8 Buttontyperotatel,9 Buttontyperotater,Ten Buttontypescaleup, One Buttontypescaledown, A - }buttontype; - @interfaceViewcontroller () the@property (Weak, nonatomic) Iboutlet UIView *Viewman; - - @end - + @implementationViewcontroller - //Move Direction +-(Ibaction) buttondirectionclicked: (UIButton *) Sender A { at //the length and height of the parent view -Nsinteger screenwidth =Self.view.frame.size.width; -Nsinteger screenheight =Self.view.frame.size.height; - - //Child View -CGRect rect =Self.viewMan.frame; in //Distance per move -Nsinteger offset =5; to //The parent control gets the view from the tag ID child control (component) + Switch(Sender.tag) - { the CaseButtontypedown: *RECT.ORIGIN.Y + =offset; $ if(RECT.ORIGIN.Y >=screenheight)Panax Notoginseng { -RECT.ORIGIN.Y =-Rect.size.height; the } + Break; A CaseButtontypeup: theRECT.ORIGIN.Y-=offset; + if(RECT.ORIGIN.Y <=-rect.size.height) - { $RECT.ORIGIN.Y =ScreenHeight; $ } - Break; - CaseButtontypeleft: theRect.origin.x-=offset; - if(Rect.origin.x <=-rect.size.width)Wuyi { theRect.origin.x =ScreenWidth; - } Wu Break; - CaseButtontyperight: AboutRect.origin.x + =offset; $ if(Rect.origin.x >=screenwidth) - { -rect.origin.x =-Rect.size.width; - } A Break; + } theSelf.viewMan.frame =rect; - } $ the //Rotate the-(Ibaction) buttonrotateclicked: (UIButton *) Sender the { the //child View the coordinate matrix of this control -Cgaffinetransform form =Self.viewMan.transform; in Switch(Sender.tag) { the CaseButtontyperotatel: theform = cgaffinetransformrotate (form,-m_2_pi/2); About Break; the CaseButtontyperotater: theform = cgaffinetransformrotate (form, m_2_pi/2); the Break; + } -Self.viewMan.transform =form; the }Bayi the //Scaling down the-(Ibaction) buttonscaleclicked: (UIButton *) Sender - { - //child View the coordinate matrix of this control theCgaffinetransform form =Self.viewMan.transform; theCGFloat Scalefator =0.0f; the the Switch(Sender.tag) { - CaseButtontypescaleup: theScalefator =1.2; the Break; the CaseButtontypescaledown:94Scalefator =0.8; the Break; the } theform =Cgaffinetransformscale (Form, scalefator, scalefator);98Self.viewMan.transform =form; About } - 101- (void) Viewdidload {102 [Super Viewdidload];103 //additional setup after loading the view, typically from a nib.104 } the 106- (void) didreceivememorywarning {107 [Super didreceivememorywarning];108 //Dispose of any resources the can be recreated.109 } the 111 @end
Objective-c:uiview View and component controls