1# PinchGesture
2
3**PinchGesture** is used to trigger a pinch gesture, which requires two to five fingers with a minimum 5 vp distance between the fingers.
4
5>  **NOTE**
6>
7>  This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## APIs
11
12PinchGesture(value?: { fingers?: number, distance?: number })
13
14**Atomic service API**: This API can be used in atomic services since API version 11.
15
16**Parameters**
17
18| Name| Type| Mandatory| Description|
19| -------- | -------- | -------- | -------- |
20| fingers | number | No| Minimum number of fingers to trigger a pinch. The value ranges from 2 to 5.<br>Default value: **2**<br>While more fingers than the minimum number can be pressed to trigger the gesture, only the first fingers of the minimum number participate in gesture calculation.|
21| distance | number | No| Minimum recognition distance, in vp.<br>Default value: **5**<br>**NOTE**<br> If the value is less than or equal to 0, it will be converted to the default value.|
22
23
24## Events
25
26| Name| Description|
27| -------- | -------- |
28| onActionStart(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Triggered when a pinch gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
29| onActionUpdate(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Triggered when the user moves the finger in the pinch gesture on the screen.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
30| onActionEnd(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Triggered when the fingers used for the pinch gesture are lifted.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
31| onActionCancel(event: () =&gt; void) | Triggered when a tap cancellation event is received after the pinch gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
32
33## Attributes
34
35| Name| Type   |Description                                       |
36| ----  | ------  | ---------------------------------------- |
37| tag<sup>11+</sup>   | string  | Tag for the pinch gesture. It is used to distinguish the gesture during custom gesture recognition.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
38| allowedTypes<sup>14+</sup> | Array\<[SourceTool](ts-gesture-settings.md#sourcetool9)> | Allowed event input types for the pinch gesture.<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
39
40## Example
41
42This example demonstrates the recognition of a three-finger pinch gesture using **PinchGesture**.
43
44```ts
45// xxx.ets
46@Entry
47@Component
48struct PinchGestureExample {
49  @State scaleValue: number = 1
50  @State pinchValue: number = 1
51  @State pinchX: number = 0
52  @State pinchY: number = 0
53
54  build() {
55    Column() {
56      Column() {
57        Text('PinchGesture scale:\n' + this.scaleValue)
58        Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')')
59      }
60      .height(200)
61      .width(300)
62      .padding(20)
63      .border({ width: 3 })
64      .margin({ top: 100 })
65      .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
66      // The gesture event is triggered by pinching three fingers together.
67      .gesture(
68      PinchGesture({ fingers: 3 })
69        .onActionStart((event: GestureEvent) => {
70          console.info('Pinch start')
71        })
72        .onActionUpdate((event: GestureEvent) => {
73          if (event) {
74            this.scaleValue = this.pinchValue * event.scale
75            this.pinchX = event.pinchCenterX
76            this.pinchY = event.pinchCenterY
77          }
78        })
79        .onActionEnd((event: GestureEvent) => {
80          this.pinchValue = this.scaleValue
81          console.info('Pinch end')
82        })
83      )
84    }.width('100%')
85  }
86}
87```
88
89 ![en-us_image_0000001174582848](figures/en-us_image_0000001174582848.png)
90