#盲盒+码# HarmonyOS应用API手势方法-LongPressGesture

鸿蒙时代
发布于 2022-11-25 16:20
浏览
0收藏

【本文正在参加「盲盒」+码有奖征文活动】(https://ost.51cto.com/posts/19288)
一、LongPressGesture
描述:用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。

Api:从API Version 7开始支持

接口:LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number })

参数:
#盲盒+码# HarmonyOS应用API手势方法-LongPressGesture-鸿蒙开发者社区
事件:
#盲盒+码# HarmonyOS应用API手势方法-LongPressGesture-鸿蒙开发者社区
二、实例代码:

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

  build() {
    Column() {
      Text('LongPress onAction:' + this.count).fontSize(28)
        // 单指长按文本触发该手势事件
        .gesture(
        LongPressGesture({ repeat: true })
          // 由于repeat设置为true,长按动作存在时会连续触发,触发间隔为duration(默认值500ms)
          .onAction((event: GestureEvent) => {
            if (event.repeat) {
              this.count++;
            }
          })
            // 长按动作一结束触发
          .onActionEnd(() => {
            this.count = 0;
          })
        )
    }
    .height(200)
    .width(300)
    .padding(20)
    .border({ width: 3 })
    .margin(30)
  }
}

三、效果图
#盲盒+码# HarmonyOS应用API手势方法-LongPressGesture-鸿蒙开发者社区
四、代码地址
(https://gitee.com/jltfcloudcn/jump_to/tree/master/TapGesture)

标签
LongPressGesture.docx 39.67K 8次下载
收藏
回复
举报
回复
    相关推荐