参考“旋转手势(RotationGesture)”:RotationGesture(value?:{fingers?:number; angle?:number})旋转手势用于触发旋转手势事件,拥有两个可选参数:fingers:用于声明触发旋转手势所需要的最少手指数量,最小值为2,最大值为5,默认值为2。angle:用于声明触发旋转手势的最小改变度数,单位为deg,默认值为1。以在Text组件上绑定旋转手势实现组件的旋转为例,可以通过在旋转手势的回调函数中获取旋转角度,从而实现组件的旋转:// xxx.ets @Entry @Component struct Index { @State angle: number = 0; @State rotateValue: number = 0; build() { Column() { Text('RotationGesture angle:' + this.angle).fontSize(28) // 在组件上绑定旋转布局,可以通过修改旋转角度来实现组件的旋转 .rotate({ angle: this.angle }) .gesture( RotationGesture() .onActionStart((event: GestureEvent|undefined) => { console.info('RotationGesture is onActionStart'); }) // 当旋转手势生效时,通过旋转手势的回调函数获取旋转角度,从而修改组件的旋转角度 .onActionUpdate((event: GestureEvent|undefined) => { if(event){ this.angle = this.rotateValue + event.angle; } console.info('RotationGesture is onActionEnd'); }) // 当旋转结束抬手时,固定组件在旋转结束时的角度 .onActionEnd(() => { this.rotateValue = this.angle; console.info('RotationGesture is onActionEnd'); }) .onActionCancel(() => { console.info('RotationGesture is onActionCancel'); }) ) .height(200) .width(300) .padding(20) .border({ width: 3 }) .margin(100) } } }
参考“旋转手势(RotationGesture)”:RotationGesture(value?:{fingers?:number; angle?:number})
旋转手势用于触发旋转手势事件,拥有两个可选参数:fingers:用于声明触发旋转手势所需要的最少手指数量,最小值为2,最大值为5,默认值为2。angle:用于声明触发旋转手势的最小改变度数,单位为deg,默认值为1。以在Text组件上绑定旋转手势实现组件的旋转为例,可以通过在旋转手势的回调函数中获取旋转角度,从而实现组件的旋转: