diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md index 8174f0054595ed1ced2a694967e9e193f3909932..b66e4988812db9eddc0f6c238d8db6f9121d9835 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md @@ -1,6 +1,6 @@ # LongPressGesture -用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。 +用于触发长按手势事件,触发长按手势的最少手指数为1,最短长按时间为500毫秒。 > **说明:** > @@ -36,24 +36,31 @@ LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number @Entry @Component struct LongPressGestureExample { - @State count: number = 0 + @State count: number = 0; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('LongPress onAction:' + this.count) + 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(60).border({ width:1 }).margin(30) - .gesture( - LongPressGesture({ repeat: true }) - // 长按动作存在会连续触发 - .onAction((event: GestureEvent) => { - if (event.repeat) { this.count++ } - }) - // 长按动作一结束触发 - .onActionEnd(() => { - this.count = 0 - }) - ) + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin(30) } } ```