#鸿蒙通关秘籍#如何实现可重复触发的长按手势?

HarmonyOS
2024-12-04 14:37:16
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
JSON寒霜满地

通过LongPressGesture,可以实现在Text组件上绑定可重复触发的长按手势。将repeat参数设置为true,即可实现重复触发功能。查看完整代码如下:

@Entry
@Component
struct Index {
  @State count: number = 0;

  build() {
    Column() {
      Text('LongPress OnAction:' + this.count).fontSize(28)
        .gesture(
          LongPressGesture({ repeat: true })
           .onAction((event: GestureEvent|undefined) => {
             if(event){
               if (event.repeat) {
                 this.count++;
               }
             }
           })
           .onActionEnd(() => {
             this.count = 0;
           })
        )
    }
    .height(200)
    .width(250)
    .padding(20)
    .border({ width: 3 })
    .margin(30)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-04 16:37:44
相关问题
长按事件如何重复触发
2778浏览 • 1回复 待解决
Canvas如何触发刷新重复绘制?
1615浏览 • 1回复 待解决