ts-basic-gestures-tapgesture.md 1.9 KB
Newer Older
Z
zengyawen 已提交
1
# TapGesture
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
**TapGesture** is used to trigger a tap gesture with one, two, or more taps.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
>  **NOTE**
6
>
E
ester.zhou 已提交
7
>  This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10 11

## APIs

E
ester.zhou 已提交
12
TapGesture(value?: { count?: number, fingers?: number })
Z
zengyawen 已提交
13

E
ester.zhou 已提交
14 15 16 17
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
18 19
| count | number | No| Number of consecutive taps. If the value is less than 1 or is not set, the default value is used.<br>Default value: **1**<br>**NOTE**<br>If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.|
| fingers | number | No| Number of fingers required to trigger a tap. The value ranges from 1 to 10. If the value is less than 1 or is not set, the default value is used.<br>Default value: **1**<br>**NOTE**<br>1. When multi-finger is configured, if the number of fingers used for tap does not reach the specified number within 300 ms after the first finger is tapped, the gesture fails to be recognized.<br>2. Gesture recognition fails if the number of fingers used for tap exceeds the configured number.|
Z
zengyawen 已提交
20 21 22 23


## Events

E
ester.zhou 已提交
24
| Name| Description|
Z
zengyawen 已提交
25
| -------- | -------- |
E
ester.zhou 已提交
26
| onAction(event: (event?: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Callback invoked when a tap gesture is recognized.|
Z
zengyawen 已提交
27 28 29 30


## Example

31 32
```ts
// xxx.ets
Z
zengyawen 已提交
33 34 35 36 37 38
@Entry
@Component
struct TapGestureExample {
  @State value: string = ''

  build() {
E
ester.zhou 已提交
39 40 41 42 43 44 45 46 47
    Column() {
      // The gesture event is triggered by double-tapping.
      Text('Click twice').fontSize(28)
        .gesture(
        TapGesture({ count: 2 })
          .onAction((event: GestureEvent) => {
            this.value = JSON.stringify(event.fingerList[0])
          })
        )
Z
zengyawen 已提交
48 49
      Text(this.value)
    }
E
ester.zhou 已提交
50 51 52 53 54
    .height(200)
    .width(300)
    .padding(20)
    .border({ width: 3 })
    .margin(30)
Z
zengyawen 已提交
55 56 57 58
  }
}
```

Z
zengyawen 已提交
59
![en-us_image_0000001256858417](figures/en-us_image_0000001256858417.gif)