harmony 鸿蒙TapGesture
TapGesture
TapGesture is used to trigger a tap gesture with one, two, or more taps.
NOTE
This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
APIs
TapGesture(value?: TapGestureParameters)
Triggers a tap gesture with one or more taps. When the gesture is triggered by a keyboard or gamepad, the value of SourceTool is Unknown.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
value | TapGestureParameters | No | Parameters related to the tap gesture. |
TapGestureParameters12+
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Name | Type | Mandatory | Description |
---|---|---|---|
count | number | No | Number of consecutive taps. If the value is less than 1 or is not set, the default value is used. Default value: 1 NOTE 1. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms. 2. If the distance between the last tapped position and the current tapped position exceeds 60 vp, gesture recognition fails. In multi-finger scenarios, the tapped position is the average position of all fingers involved in the gesture response. |
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. Default value: 1 NOTE 1. For a multi-finger gesture, recognition fails if the required number of fingers is not pressed within 300 ms after the first finger; when fingers are lifted, if the remaining number of fingers is below the threshold after lifting, all fingers must be lifted within 300 ms for the gesture to be successfully recognized. 2. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized. |
distanceThreshold | number | No | Movement threshold for the tap gesture. If the value is less than or equal to 0 or is not set, the default value is used. Default value: 2^31-1 NOTE If the finger movement exceeds the preset movement threshold, the tap gesture recognition fails. If the default threshold is used during initialization and the finger moves beyond the component’s touch target, the tap gesture recognition fails. |
isFingerCountLimited15+ | boolean | No | Whether to enforce the exact number of fingers touching the screen. With the value true, the gesture recognition fails if the number of fingers touching the screen does not match the configured value of fingers. In multi-tap events (where the count parameter is greater than 1), each tap must have the same number of fingers as the configured value; otherwise, the gesture recognition fails. Default value: false |
Events
Name | Description |
---|---|
onAction(event: (event: GestureEvent) => void) | Callback invoked when a tap gesture is recognized. Atomic service API: This API can be used in atomic services since API version 11. |
Attributes
Name | Type | Description |
---|---|---|
tag11+ | string | Tag for the tap gesture. It is used to distinguish the gesture during custom gesture judgment. Atomic service API: This API can be used in atomic services since API version 11. |
allowedTypes14+ | Array<SourceTool> | Allowed event input types for the tap gesture. Atomic service API: This API can be used in atomic services since API version 14. |
Example
This example demonstrates the recognition of a double-tap gesture using TapGesture.
// xxx.ets
@Entry
@Component
struct TapGestureExample {
@State value: string = ''
build() {
Column() {
// The gesture event is triggered by double-tapping.
Text('Click twice').fontSize(28)
.gesture(
TapGesture({ count: 2 })
.onAction((event: GestureEvent) => {
if (event) {
this.value = JSON.stringify(event.fingerList[0])
}
})
)
Text(this.value)
}
.height(200)
.width(300)
.padding(20)
.border({ width: 3 })
.margin(30)
}
}
你可能感兴趣的鸿蒙文章
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦