A frame is a required property for each view, which represents the
当前视图 location and size, without setting him,
当前视图 is not visible.
Position requires a reference to determine, in mathematics we use a coordinate system to determine the location of a point in the coordinate system, iOS has his unique coordinate system, such as:
右x positive direction and the
下y positive direction.
父视图的坐标系determined by the criteria.
Bounds is a property of each view, which we do not normally set, and he also represents position and size;
Each view has its own coordinate system, and the coordinate system defaults to its own
左上角 coordinate origin, and all the sub-views are datum points in that coordinate system
The position of the bounds represents the position of the
子视图 current view
左上角 ; the size of the bounds represents the size of the current view;
左上角no longer (0,0), but the changed coordinates, the coordinate system changes, then all
位置will be changed
中心点continue to remain unchanged, the length of the width of the change, through the bounds to modify the length of the width of the image is like a center point for the reference point to the length and width of both sides of the same scale;
View A is the topmost view, so his message is as follows:
SIZE:550 * 400
Size 550 * 400
Because it is view a is, it is
顶层视图 actually equivalent to
覆盖 the frame, so the position starts from the parent view (0, 0) and the size is 550*400
坐标系 there is no change in the view, that is, the current view (view A)
左上角 is all
子视图 the origin, and the size is the size of the current view.
View B is a child view of view a, so his message is as follows:
SIZE:200 * 250
SIZE:200 * 250
Because view B is a child view of view a, the frame position of view B needs to be
View A的左上角 referenced, so the position is (200, 100) and the size is 200*250
Bounds by default, the coordinate system of this view is not changed, that is, the current view (view B) is the
左上角 origin of all the child views of the current view.
This is the normal situation, that is, when the bounds is not changed, let's look at the example of changing bounds, such as:
On the basis of the previous example, when we changed the bounds of view A, view B changed the upper-left corner of view a, and this time we looked at the upper-left corner of view A is not the origin of the coordinates , But the coordinates we set through bounds, i.e. (0, 100);
On the basis of view B's frame not being preserved, we moved up the position of view B by 100.
On the basis of the first example, after changing the x in bounds, the following:
1, frame regardless of position or size, change is
2. The frame position is
父视图 referenced by the coordinate system, thus determining the position of the current view in the parent view
3, when the frame size changes, the current view
左上角 position will not change, but
2, bounds change position, the change is
子视图 the position,
自身 no impact; in fact, it is changing the original point of the coordinate system itself, the default itself is the upper left corner of the coordinate system
3, when the size of the bounds changes, the current view
中心点 will not change, the current view
大小 changes, it looks like the effect of the
Red View Original frame is
CGRectMake (200, 200, 100, 100)];
Change bounds to
View.bounds=cgrectmake (0, 100, 200, 200);
FRAME (origin = (x =, y = $), size = (width = max, height = 200))
Place the same size yellow button on the Red view,
Btn.frame=cgrectmake (0, 0, 200, 200);
It is not useful to click on a button other than the Red view, only the active part will be effective.
IOS frame and bounds and frame and bounds differences