1 view contoller的初始化
initWithFrame: self.view.bounds or self.view.frame or CGRectMake(0, 0, 100, 100)
bound和frame是两个结构体变量:
struct CGRect { CGPoint origin; CGSize size; }; typedef struct CG_BOXABLE CGRect CGRect;
//--------------------------------------------
struct
CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct CG_BOXABLE CGPoint CGPoint;
//---------------------------------------------
struct CGSize {
CGFloat width;
CGFloat height;
};
---------------------------------------------
CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
CGRect rect;
rect.origin.x = x; rect.origin.y = y;
rect.size.width = width; rect.size.height = height;
return rect;
}
关于Frame和bounds:
As the documentation clarifies, the frame of a view is a structure, a CGRect, that defines the size of the view and its position in the view‘s superview(依赖父view), the superview‘s coordinate system. Take a look at the following diagram for clarification.The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

The bounds property of a view defines the size of the view and its position in the view‘s own coordinate system. This means that in most cases the origin of the bounds of a view are set to {0,0} as shown in the following diagram. The view‘s bounds is important for drawing the view.The bounds rectangle, which describes the view’s location and size in its own coordinate system.

This means a few things:
frame and bounds are the same.frame or bounds, the other value is updated to match. Generally it’s better to modify bounds plus center and transform, and let UIKit calculate the framefor you.CGRectMake 设置原点和宽高,但是坐标系要看它是附在哪个view上。

setBounds的作用是:强制将自己(view1)坐标系的左上角点,改为(-20,-20)。那么view1的原点,自然就向在右下方偏移(20,20)
原文:https://www.cnblogs.com/8335IT/p/15007726.html