1# Transformation 2 3Transformation attributes allow you to rotate, translate, scale, or transform a component. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8 9## rotate 10 11rotate(value: RotateOptions) 12 13Rotates the component. 14 15**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets. 16 17**Atomic service API**: This API can be used in atomic services since API version 11. 18 19**System capability**: SystemCapability.ArkUI.ArkUI.Full 20 21**Parameters** 22 23| Name| Type | Mandatory| Description | 24| ------ | --------------------------------------- | ---- | ------------------------------------------------------------ | 25| value | [RotateOptions](#rotateoptions) | Yes | How the component rotates in the coordinate system (as shown below) with the upper left corner of the component as the coordinate origin. (x, y, z) specifies a vector as the axis of rotation.<br>The axis and center of rotation are set based on the coordinate system, which remains where it is when the component is moved.<br>Default value:<br>{<br>x: 0,<br>y: 0,<br>z: 0,<br>centerX: '50%',<br>centerY: '50%'<br>centerZ: 0,<br>perspective: 0<br>}<br><br>Since API version 10, **CenterZ** and **perspective** are supported in ArkTS widgets.| 26 27## translate 28 29translate(value: TranslateOptions) 30 31Translates the component. 32 33**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets. 34 35**System capability**: SystemCapability.ArkUI.ArkUI.Full 36 37**Parameters** 38 39| Name| Type | Mandatory| Description | 40| ------ | --------------------------------------------- | ---- | ------------------------------------------------------------ | 41| value | [TranslateOptions](#translateoptions) | Yes | How the component is translated in the coordinate system (as shown below) with the upper left corner of the component as the coordinate origin. Values of **x**, **y**, and **z** indicate the translation distance along the respective axis. A positive value indicates a forward movement towards the respective axis, and a negative value indicates a backward movement towards the respective axis. The translation distance can be a number or a string (for example, **'10px'** or **'10%'**).<br>Default value:<br>{<br>x: 0,<br>y: 0,<br>z: 0<br>}<br><br>**NOTE**<br>When the component is translated along the z-axis, the position of the observation point remains unchanged. As such, the component appears larger when the value of **z** places it closer to the observation point and smaller when the value of **z** places it further away from the observation point.<br> | 42 43## scale 44 45scale(value: ScaleOptions) 46 47Scales the component. 48 49**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets. 50 51**Atomic service API**: This API can be used in atomic services since API version 11. 52 53**System capability**: SystemCapability.ArkUI.ArkUI.Full 54 55**Parameters** 56 57| Name| Type | Mandatory| Description | 58| ------ | ------------------------------------- | ---- | ------------------------------------------------------------ | 59| value | [ScaleOptions](#scaleoptions) | Yes | Scale ratio along the x-, y-, and z-axis. The default value is **1**. **centerX** and **centerY** are used to set the scale center point.<br>Default value:<br>{<br>x: 1,<br>y: 1,<br>z: 1,<br>centerX:'50%',<br>centerY:'50%'<br>} | 60 61## transform 62 63transform(value: Matrix4Transit) 64 65Sets the transformation matrix of the component. 66 67**Atomic service API**: This API can be used in atomic services since API version 11. 68 69**System capability**: SystemCapability.ArkUI.ArkUI.Full 70 71**Parameters** 72 73| Name| Type | Mandatory| Description | 74| ------ | --------------------------------------- | ---- | ------------------------ | 75| value | [Matrix4Transit](../js-apis-matrix4.md) | Yes | Transformation matrix of the component.| 76 77## RotateOptions 78 79**Widget capability**: This API can be used in ArkTS widgets since API version 9. 80 81**Atomic service API**: This API can be used in atomic services since API version 11. 82 83| Name | Type | Mandatory| Description | 84| ------------------------- | -------------------------- | ---- | ------------------------------------------------------------ | 85| x | number | No | X coordinate of the rotation axis vector. | 86| y | number | No | Y coordinate of the rotation axis vector. | 87| z | number | No | Z coordinate of the rotation axis vector. | 88| angle | number \| string | Yes | Angle to rotate. A positive angle indicates a clockwise rotation, and a negative angle indicates a counterclockwise rotation. The value can be of the string type, for example, **'90deg'**.| 89| centerX | number \| string | No | X coordinate of the center point. | 90| centerY | number \| string | No | Y coordinate of the center point. | 91| centerZ<sup>10+</sup> | number | No | Z-axis anchor, that is, the z-component of the 3D rotation center point. | 92| perspective<sup>10+</sup> | number | No | Distance from the user to the z=0 plane.<br>The axis and center of rotation are set based on the coordinate system, which remains where it is when the component is moved.| 93 94## TranslateOptions 95 96**Widget capability**: This API can be used in ArkTS widgets since API version 9. 97 98**Atomic service API**: This API can be used in atomic services since API version 11. 99 100| Name| Type | Mandatory| Description | 101| ---- | -------------------------- | ---- | --------------- | 102| x | number \| string | No | Translation distance along the x-axis.| 103| y | number \| string | No | Translation distance along the y-axis.| 104| z | number \| string | No | Translation distance along the z-axis.| 105 106## ScaleOptions 107 108**Widget capability**: This API can be used in ArkTS widgets since API version 9. 109 110**Atomic service API**: This API can be used in atomic services since API version 11. 111 112| Name | Type | Mandatory| Description | 113| ------- | -------------------------- | ---- | ------------------------------------------------------------ | 114| x | number | No | Scale ratio along the x-axis. x > 1: The component is scaled up along the x-axis.<br>0 < x < 1: The component is scaled down along the x-axis.<br>x < 0: The component is scaled in the reverse direction of the x-axis.| 115| y | number | No | Scale ratio along the y-axis. y > 1: The component is scaled up along the y-axis.<br>0 < y < 1: The component is scaled down along the y-axis.<br>y < 0: The component is scaled in the reverse direction of the y-axis.| 116| z | number | No | Scale ratio along the z-axis. z > 1: The component is scaled up along the z-axis.<br>0 < z < 1: The component is scaled down along the z-axis.<br>z < 0: The component is scaled in the reverse direction of the z-axis.| 117| centerX | number \| string | No | X coordinate of the center point. | 118| centerY | number \| string | No | Y coordinate of the center point. | 119 120> **NOTE** 121> 122> If the **rotate** and **scale** attributes are both set for a component, the values of **centerX** and **centerY** conflict. In this case, the one that is set later in time prevails. 123 124## Example 125 126```ts 127// xxx.ets 128import matrix4 from '@ohos.matrix4' 129 130@Entry 131@Component 132struct TransformExample { 133 build() { 134 Column() { 135 Text('rotate').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14) 136 Row() 137 .rotate({ 138 x: 0, 139 y: 0, 140 z: 1, 141 centerX: '50%', 142 centerY: '50%', 143 angle: 300 144 }) // The component rotates around the center point of the rotation axis (0,0,1) clockwise by 300 degrees. 145 .width(100).height(100).backgroundColor(0xAFEEEE) 146 147 Text('translate').width('90%').fontColor(0xCCCCCC).padding(10).fontSize(14) 148 Row() 149 .translate({ x: 100, y: 10 }) // The component translates by 100 along the x-axis and by 10 along the y-axis. 150 .width(100).height(100).backgroundColor(0xAFEEEE).margin({ bottom: 10 }) 151 152 Text('scale').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14) 153 Row() 154 .scale({ x: 2, y: 0.5}) // The height and width are doubled. The z-axis has no effect in 2D mode. 155 .width(100).height(100).backgroundColor(0xAFEEEE) 156 157 Text('Matrix4').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14) 158 Row() 159 .width(100).height(100).backgroundColor(0xAFEEEE) 160 .transform(matrix4.identity().translate({ x: 50, y: 50 }).scale({ x: 1.5, y: 1 }).rotate({ 161 x: 0, 162 y: 0, 163 z: 1, 164 angle: 60 165 })) 166 }.width('100%').margin({ top: 5 }) 167 } 168} 169``` 170 171 172