未验证 提交 f0054d23 编写于 作者: L luoying_ace 提交者: Gitee

update zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md.

Signed-off-by: Nluoying_ace <luoying19@huawei.com>
上级 0f755a16
# LongPressGesture # LongPressGesture
用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。 用于触发长按手势事件,触发长按手势的最少手指数为1,最短长按时间为500毫秒。
> **说明:** > **说明:**
> >
...@@ -36,24 +36,31 @@ LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number ...@@ -36,24 +36,31 @@ LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number
@Entry @Entry
@Component @Component
struct LongPressGestureExample { struct LongPressGestureExample {
@State count: number = 0 @State count: number = 0;
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { Column() {
Text('LongPress onAction:' + this.count) 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(60).border({ width:1 }).margin(30) .height(200)
.gesture( .width(300)
LongPressGesture({ repeat: true }) .padding(20)
// 长按动作存在会连续触发 .border({ width: 3 })
.onAction((event: GestureEvent) => { .margin(30)
if (event.repeat) { this.count++ }
})
// 长按动作一结束触发
.onActionEnd(() => {
this.count = 0
})
)
} }
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册