In-depth relationships between frame, bounds, center, and transform coordinates in IOS development
If you have any questions, add qq chat group: 390438081
My QQ: 604886384 (indicating your intention)
: Niuting823
1.1 frame attributes
A. What is frame?
Type: CGRect struct (size origin)
Purpose: Position of the Left vertex of the view in the coordinate system of the parent view, and the width and height occupied by the view in the parent View
B. The frame is modified directly. How do other attributes change?
Bounds: Yes
Center: Yes
Transform: No
C. When to use frame
When adding a View to the parent view, you must set the frame attribute.
1.2 bounds attributes
A. What is the bounds attribute?
Type: CGRect struct
Purpose: describes the reference value of the vertex of the current Coordinate System of the view and the size of the view.
B. How other attributes change when the bounds attribute is directly modified
Frame: Yes
Center: No
Transform: No
C. When are bounds attributes?
When you need to define a view and read the size of the parent view, the size in the bounds attribute of the parent view is used.
When you modify the position of the subview In a view, you can modify the starting point of the bounds Coordinate System of the view so that the position of the subview is offset to achieve the moving effect.
1.3 center attributes
A. What is the center attribute?
Type: CGPoint type
Role: describes the position of the View Center in the parent view coordinate system.
B. Directly modify the center attribute and change other attributes.
Frame: The value related to coordinates changes.
Bounds: No
Transform: No
C. When to use center
When you need to modify the position of the view, that is, the displacement
1.4 transform attributes
A. What is the transform attribute?
Type: CGAffineTransform
Purpose: Describe the deformation status of the view.
B. Modify transform directly. How do other attributes change?
Frame: Yes
Bounds: No
Center: No
C. When to use transform
You can modify this attribute when the view needs to be deformed (scaled or rotated ).
Conclusion: before deformation, the frame and bounds maintain the consistency of the changes. After deformation, the frame represents the appearance displayed in the view, so different appearance states are recorded as deformation occurs, so it will change, but bounds is not used to record the performance, but the record size, so it will not change, bounds and center are independent of the values outside the deformation coordinate system, transform records changes to the drawing Coordinate System
To get the size, read bounds, locate the location, and find the frame