1# 图形变换 2 3> **说明:** 4> 5> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 6 7 8## 属性 9 10 11| 名称 | 参数类型 | 描述 | 12| --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | 13| rotate | {<br/>x?: number,<br/>y?: number,<br/>z?: number,<br/>angle?: number \| string,<br/>centerX?: number \| string,<br/>centerY?: number \| string<br/>} | (x, y, z)指定一个矢量,表示旋转轴,正角度为顺时针转动,负角度为逆时针转动,默认值为0,同时可以通过centerX和centerY设置旋转的中心点。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0,<br/>z: 0,<br/>angle: 0,<br/>centerX: '50%',<br/>centerY: '50%'<br/>} | 14| translate | {<br/>x?: number \| string,<br/>y?: number \| string,<br/>z? : number \| string<br/>} | 可以分别设置X轴、Y轴、Z轴的平移距离,距离的正负控制平移的方向,默认值为0。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0,<br/>z: 0<br/>} | 15| scale | {<br/>x?: number,<br/>y?: number,<br/>z?: number,<br/>centerX?: number \| string,<br/>centerY?: number \| string<br/>} | 可以分别设置X轴、Y轴、Z轴的缩放比例,默认值为1,同时可以通过centerX和centerY设置缩放的中心点。<br/>默认值:<br/>{<br/>x: 1,<br/>y: 1,<br/>z: 1,<br/>centerX:'50%',<br/>centerY:'50%'<br/>} | 16| transform | matrix: Matrix4 | 设置当前组件的变换矩阵。 | 17 18 19## 示例 20 21```ts 22// xxx.ets 23import Matrix4 from '@ohos.matrix4' 24 25@Entry 26@Component 27struct TransformExample { 28 29 build() { 30 Column() { 31 Text('rotate').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) 32 Row() 33 .rotate({ 34 x: 1, 35 y: 1, 36 z: 1, 37 centerX: '50%', 38 centerY: '50%', 39 angle: 300 40 }) // 组件以(1,1,1)为旋转轴,中心点顺时针旋转 300度 41 .width(100).height(100).backgroundColor(0xAFEEEE) 42 43 Text('translate').width('90%').fontColor(0xCCCCCC).padding(10).fontSize(30) 44 Row() 45 .translate({ x: 100, y: 5 }) // x轴平移100,y轴平移5 46 .width(100).height(100).backgroundColor(0xAFEEEE).margin({bottom:10}) 47 48 Text('scale').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) 49 Row() 50 .scale({ x: 2, y: 0.5 }) // 高度缩小一倍,宽度放大一倍,z轴在2D下无效果 51 .width(100).height(100).backgroundColor(0xAFEEEE) 52 53 Text('Matrix4').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) 54 Row() 55 .width(100).height(100).backgroundColor(0xAFEEEE) 56 .transform(Matrix4.identity().translate({ x: 100, y: 100, z: 30 })) 57 }.width('100%').margin({ top: 5 }) 58 } 59} 60``` 61 62 63