#鸿蒙通关秘籍#如何实现互斥识别的组合手势?

HarmonyOS
2024-12-05 15:33:50
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
BinaryBard

互斥识别的组合手势中只需有一个手势被识别成功,其他手势则无法被识别。在HarmonyOS,只需将GestureMode设为Exclusive即可实现这种机制。

下面是一个实现互斥识别的组合手势示例,其中包括单击和双击手势:

// xxx.ets
@Entry
@Component
struct Index {
  @State count1: number = 0;
  @State count2: number = 0;

  build() {
    Column() {
      Text('Exclusive gesture\n' + 'tapGesture count is 1:' + this.count1 + '\ntapGesture count is 2:' + this.count2 + '\n')
        .fontSize(28)
    }
    .height(200)
    .width('100%')
    .gesture(
      GestureGroup(GestureMode.Exclusive,
        TapGesture({ count: 1 })
          .onAction(() => {
            this.count1++;
          }),
        TapGesture({ count: 2 })
          .onAction(() => {
            this.count2++;
          })
      )
    )
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-05 16:02:03
相关问题
#鸿蒙学习大百科#什么是组合手势
882浏览 • 1回复 待解决
语音识别的方法有哪些?
1143浏览 • 1回复 待解决