first, UIView Common Properties(1) @property (nonatomic,readonly) UIView *superview;//Get your own parent control object(2) @property (nonatomic,readonly,copy) UIView *subviews;//gets all of its child control objects(3) The ID of the @property (nonatomic) Nsinteger tag;//control is identified, and the parent control can find the corresponding child control via tag, which defaults to 0(4) position and dimensions of the rectangle where the @property (nonatomic) CGRect frame;//Control is located (in the upper-left corner of the parent control as the origin of the coordinates)(5) position and dimensions of the rectangle where the @property (nonatomic) CGRect bounds;//Control is located (the origin of the coordinates in its upper-left corner, the x\y of bounds is always 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 of the coordinates)(7) Deformation properties of the @property (nonatomic) Cgaffinetransform transform;//control (you can set properties such as 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 factorB. Retraction: Cgaffinetransform cgaffinetransformrotate (cgaffinetransform t,cgfloat angle)angle: Rotation degreec. Inversion: Cgaffinetransform Cgaffinetransforminvert (Cgaffinetransform t) d. Two matrix affine for a new matrix:cgaffinetransform cgaffinetransformconcat (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;
};
second, the 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, with a total of 6 options:uibuttontypecustom: No type, the content of the button needs to be customizeduibuttontyperoundedrect: Round rectangular borderuibuttontypedetaildisclosure:uibuttontypeinfolight:Uibuttontypeinfodark:Uibuttontypecontactadd:
Works: Boxman
1 #import "ViewController.h" 2 typedef enum 3 {4 buttontypeleft=1, 5 buttontyperight, 6 buttontypeup, 7 Buttontypedown, 8 Buttontyperotatel, 9 Buttontyperotater, ten buttontypescaleup, one buttontypescal Edown,}buttontype; @interface Viewcontroller () @property (weak, nonatomic) Iboutlet UIView *viewman; @end @implementation Viewcontroller 20//Moving Direction-(ibaction) buttondirectionclicked: (UIButton *) Sender 22 { 23//Parent view length and height of nsinteger screenwidth = self.view.frame.size.width; Nsinteger screenheight = self.view.frame.size.height; 26 27//Sub-view cgrect rect = self.viewMan.frame; 29//Movement distance Nsinteger offset = 5; 31//Parent control gets view by tag ID child control (component) switch (sender.tag) buttontypedown:35 rect.or IGIN.Y + = offset; if (rect.origin.y >= screenheight) PNs {rect.origin.y =-rect.size.height; 39 }; buttontypeup:42 RECT.ORIGIN.Y-= offset; if (rect.origin.y <=-rect.size.height), {rect.origin.y = ScreenHeight; A. buttontypeleft:49 rect.origin.x-= offset; if (rect.origin.x <=-rect.size.width) {rect.origin.x = ScreenWidth; 5 3} The break; buttontyperight:56 rect.origin.x + = offset; Rect.origin.x >= screenwidth) (+ rect.origin.x =-rect.size.width; 6 0}; Self.viewMan.frame = rect; 64} 65 66//Rotation-(ibaction) buttonrotateclicked: (UIButton *) Sender 68 {69//Sub-view the coordinate matrix of this control is Cgaffinetransform form = Self.viewMan.transform; Switch (sender.tag) {buttontyperotatel:73 case form = cgaffinetransformrotate (form,-M_2_PI/2); a break; The case buttontyperotater:76 form = cgaffinetransformrotate (form, M_2_PI/2); a break; Self.viewMan.transform = form; 80} 81 82//Indent-(Ibaction) buttonscaleclicked: (UIButton *) Sender 84 {85//Sub-view the coordinate matrix of this control cgaffinetransform form = Self.viewMan.transform; CGFloat scalefator = 0.0f; (Sender.tag) {buttontypescaleup:91 scalefator = 1.2; Eak buttontypescaledown:94 scalefator = 0.8; a break; (Cgaffinetransformscale) (form, Scalefator, scalefator); 98 self.viewMan.transform = form; }100 101-(void) Viewdidload {102 [Super viewdidload];103//Do any additional setup after loading the view, Ty Pically from a nib.104}105 106-(void) didreceivememorywarning {107 [Super didreceivememorywarning];108 Dispose of any resources the can be recreated.109}110 111 @end
Ios:uiview View and component controls