Rect Transform
The Rect Transform component is the 2D layout counterpart of the Transform component. Where Transform represents a single point, Rect Transform represent a rectangle that a UI element can be placed inside. If the parent of a Rect Transform is also a Rect Transform, the child Rect Transform can also specify how it should be positioned and sized relative to the parent rectangle.
Rect Transform组件是Transform组件在2D布局下的对应版本。Transform表示单个点,Rect Transform表示一个UI元素可以放进去的矩形。如果Rect Transform的父节点也是Rect Transform,那么这个Rect Transform还可以指示它相对于父矩形的位置和尺寸。
Properties
属性
Property: | Function: |
---|---|
Pos (X, Y, Z) | Position of the rectangle’s pivot point relative to the anchors. |
Width/Height | Width and height of the rectangle. |
Left, Top, Right, Bottom | Positions of the rectangle’s edges relative to their anchors. This can be thought of as padding inside the rectangle defined by the anchors. Shown in place of Pos and Width/Height when the anchors are separated (see below). |
Anchors | The anchor points for the lower left corner and the upper right corner of the rectangle. |
Min | The anchor point for the lower left corner of the rectangle defined as a fraction of the size of the parent rectangle. 0,0 corresponds to anchoring to the lower left corner of the parent, while 1,1 corresponds to anchoring to the upper right corner of the parent. |
Max | The anchor point for the upper right corner of the rectangle defined as a fraction of the size of the parent rectangle. 0,0 corresponds to anchoring to the lower left corner of the parent, while 1,1 corresponds to anchoring to the upper right corner of the parent. |
Pivot | Location of the pivot point around which the rectangle rotates, defined as a fraction of the size of the rectangle itself. 0,0 corresponds to the lower left corner while 1,1 corresponds to the upper right corner. |
Rotation | Angle of rotation (in degrees) of the object around its pivot point along the X, Y and Z axis. |
Scale | Scale factor applied to the object in the X, Y and Z dimensions. |
属性: | 功能: |
---|---|
Pos (X, Y, Z) | 矩形的pivot相对于锚的位置 |
Width/Height | 矩形的宽度和高度 |
Left, Top, Right, Bottom |
矩形的边缘相对于他们锚的位置。这可以理解为当前矩形到由锚定义的矩形的间隔。当锚被分开的时候,他们会显示在Pos、Width/Height的位置(见下文) |
Anchors | 矩形的左下角和右上角的锚点 |
Min |
矩形左下角的锚点定义为占父矩形大小的比例。 0,0对应于锚定到父项的左下角,而1,1对应于锚定到父项的右上角 |
Max |
矩形右上角的锚点定义为占父矩形大小的比例。 0,0对应于锚定到父项的左下角,而1,1对应于锚定到父项的右上角 |
Pivot |
矩形旋转的枢轴点的位置,定义为占矩形本身大小的比例。 0,0对应于左下角,而1,1对应于右上角 |
Rotation | 物体绕X,Y,Z轴旋转的角度(以度为单位) |
Scale | 应用于对象的X,Y和Z尺寸的比例因子 |
Details
细节
Note that some RectTransform calculations are performed at the end of a frame, just before calculating UI vertices, in order to ensure that they are up to date with all the latest changes performed throughout the frame. This means that they haven’t yet been calculated for the first time in the Start callback and first Update callback.
请注意,一些RectTransform计算是在一帧的结尾处执行的,这在计算UI顶点之前在,以确保它们在整个帧中执行的所有最新更改都保持最新。 也就是说首次Start()和Update()结束时它们并没有被计算过(这两个函数的调用时机详见Behaviour生命周期)。
You can work around this by creating a Start()
callback and adding Canvas.ForceUpdateCanvases()
method to it. This will force Canvas to be updated not at the end of the frame, but when that method is called.
你可以通过创建一个Start()函数,并添加Canvas.ForceUpdateCanvases()方法来解决这个问题。 这将强制画布立即更新,而不是在帧末尾。
See the Basic Layout page for a full introduction and overview of how to use the Rect Transform.
有关如何使用Rect Transform的完整介绍和概述,请参阅Basic Layout页面。