# IOS frame and bounds and frame and bounds differences

Source: Internet
Author: User

Frame

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:

iOS coordinate system

• In the iOS coordinate system, with the upper-left corner as the coordinate origin, toward the `右` x positive direction and the `下` y positive direction.
• The position in the frame is `父视图的坐标系` determined by the criteria.`当前视图的位置`
• Similarly, by default, the coordinates of this view are `左上角` `子视图``原点`
• Change position in frame, the position of the current view changes
• Changes the size of the frame, the current view is modified to a `当前视图` `左上角` baseline size
Bounds

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;

• Changing the position in bounds has no effect on the current view, which is equivalent to changing the current view's coordinate system, and for the child view the current view is `左上角` no longer (0,0), but the changed coordinates, the coordinate system changes, then all `子视图` `位置` will be changed
• Change the size of the bounds, bounds the size of the current view of the length and width, modify the length of the width, `中心点` 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;
Frame and bounds

Like:

IOS bounds

View A is the topmost view, so his message is as follows:
Frame
origin:0, 0
SIZE:550 * 400

Bounds
origin:0, 0
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
By default, `坐标系` 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:
Frame
origin:200, 100
SIZE:200 * 250

Bounds
origin:0, 0
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:

IOS bounds

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:

IOS Bounds 3

Summarize

1, frame regardless of position or size, change is `自己` itself
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 `大小` changes
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 `缩放` same

Other:

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

Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD