What's the difference between the frame and the bounds ?
What's the difference between the frame and the bounds ?
The difference between the frame
and the bounds
of a UIView in iOS development is a fundamental concept that relates to how views are positioned and sized within their parent views and their own coordinate systems.
frame
of a UIView is a rectangle that defines the view's location and size in the coordinate system of its superview.frame
is used to position the view within its parent view. For example, if a view is placed 100 points from the left and 100 points from the top of its superview, its frame might be {100, 100, 200, 200}
for a 200x200 view.frame
changes to reflect the new position and size relative to the superview.bounds
of a UIView is a rectangle that defines the view's location and size in its own coordinate system.bounds
is used to define the internal coordinate system of the view. It is particularly useful for drawing and laying out subviews within the view.bounds
remains constant even when the view is transformed. The size of the bounds
does not change with transformations, but the content within the view may be affected.Coordinate System:
Frame
: Relative to the superview's coordinate system.Bounds
: Relative to the view's own coordinate system.Origin:
Frame
: The origin can be any point within the superview's coordinate system.Bounds
: The origin is typically (0, 0), but it can be adjusted for scrolling or other purposes.Transformations:
Frame
: Changes with transformations (e.g., rotation, scaling).Bounds
: Remains constant; transformations do not affect the bounds
.Consider a view viewA
that contains a subview viewB
. If viewA
has a frame of {50, 50, 200, 200}
, it means viewA
is positioned 50 points from the left and 50 points from the top of its superview, and it is 200x200 in size. If viewA
's bounds are {0, 0, 200, 200}
, it means the internal coordinate system of viewA
starts at (0, 0) and extends to 200x200.
If viewA
is rot...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào