#鸿蒙通关秘籍#如何在Text组件上实现旋转手势控制旋转动作?

HarmonyOS
2024-12-04 14:19:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
草药味儿

可以通过RotationGesture检测旋转手势,调整组件的旋转角度。具体代码实现如下:

@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)
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
分享
微博
QQ
微信
回复
2024-12-04 16:01:15


相关问题
HarmonyOS 如何实现旋转动
1155浏览 • 1回复 待解决
HarmonyOS 旋转动画效果
728浏览 • 1回复 待解决
HarmonyOS 组件旋转
624浏览 • 1回复 待解决
如何实现图片裁剪、旋转
1401浏览 • 1回复 待解决
HarmonyOS 如何实现Y轴旋转
677浏览 • 1回复 待解决
如何实现一个组件不停地旋转
3279浏览 • 1回复 待解决
如何实现应用的屏幕自动旋转
3088浏览 • 1回复 待解决