HarmonyOS应用API手势方法-LongPressGesture
一、LongPressGesture
描述:用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。
Api:从API Version 7开始支持
接口:LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number })
参数:
事件:
二、实例代码:
@Entry@Componentstruct 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) }}
三、效果图
四、代码地址
(HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com)