From 53829f71eba329c32821fe23fa663f51f8357df1 Mon Sep 17 00:00:00 2001 From: luoying_ace Date: Sat, 8 Oct 2022 07:31:41 +0000 Subject: [PATCH] update zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md. Signed-off-by: luoying_ace --- .../arkui-ts/ts-universal-events-touch.md | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md index f671f750b9..d6d90c84fa 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md @@ -1,6 +1,6 @@ # 触摸事件 -当手指放在组件上、滑动或从组件上移开时触发。 +当手指在组件上按下、滑动、抬起时触发。 > **说明:** > @@ -11,7 +11,7 @@ | 名称 | 是否冒泡 | 功能描述 | | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | -| onTouch(event: (event?: TouchEvent) => void) | 是 | 触摸动作触发该方法调用,event参数见[TouchEvent](#touchevent对象说明)介绍。 | +| onTouch(event: (event?: TouchEvent) => void) | 是 | 手指触摸动作触发该回调,event返回值见[TouchEvent](#touchevent对象说明)介绍。 | ## TouchEvent对象说明 @@ -45,29 +45,45 @@ @Entry @Component struct TouchExample { - @State text: string = '' - @State eventType: string = '' + @State text: string = ''; + @State eventType: string = ''; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Button('Touch').backgroundColor(0x2788D9).height(40).width(80) + Column() { + Button('Touch').height(40).width(100) .onTouch((event: TouchEvent) => { if (event.type === TouchType.Down) { - this.eventType = 'Down' + this.eventType = 'Down'; } if (event.type === TouchType.Up) { - this.eventType = 'Up' + this.eventType = 'Up'; } if (event.type === TouchType.Move) { - this.eventType = 'Move' + this.eventType = 'Move'; } - console.info(this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' - + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:(' + this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' + + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\nComponent globalPos:(' + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:' - + event.target.area.width + '\nheight:' + event.target.area.height) + + event.target.area.width + '\nheight:' + event.target.area.height; + }) + Button('Touch').height(50).width(200).margin(20) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down'; + } + if (event.type === TouchType.Up) { + this.eventType = 'Up'; + } + if (event.type === TouchType.Move) { + this.eventType = 'Move'; + } + this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' + + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\nComponent globalPos:(' + + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:' + + event.target.area.width + '\nheight:' + event.target.area.height; }) Text(this.text) - }.height(200).width(350).padding({ left: 35, right: 35, top: 35 }) + }.width('100%').padding(30) } } ``` -- GitLab