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 finger used for the pinch gesture is lift.<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**Atomic service API**: This API can be used in atomic services since API version 11.
36
37| Name| Type   |Description                                       |
38| ----  | ------  | ---------------------------------------- |
39| tag<sup>11+</sup>   | string  | Tag for the pinch gesture. It is used to distinguish the gesture during custom gesture judgment.|
40
41## Example
42
43```ts
44// xxx.ets
45@Entry
46@Component
47struct PinchGestureExample {
48  @State scaleValue: number = 1
49  @State pinchValue: number = 1
50  @State pinchX: number = 0
51  @State pinchY: number = 0
52
53  build() {
54    Column() {
55      Column() {
56        Text('PinchGesture scale:\n' + this.scaleValue)
57        Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')')
58      }
59      .height(200)
60      .width(300)
61      .padding(20)
62      .border({ width: 3 })
63      .margin({ top: 100 })
64      .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
65      // The gesture event is triggered by pinching three fingers together.
66      .gesture(
67      PinchGesture({ fingers: 3 })
68        .onActionStart((event: GestureEvent) => {
69          console.info('Pinch start')
70        })
71        .onActionUpdate((event: GestureEvent) => {
72          if (event) {
73            this.scaleValue = this.pinchValue * event.scale
74            this.pinchX = event.pinchCenterX
75            this.pinchY = event.pinchCenterY
76          }
77        })
78        .onActionEnd((event: GestureEvent) => {
79          this.pinchValue = this.scaleValue
80          console.info('Pinch end')
81        })
82      )
83    }.width('100%')
84  }
85}
86```
87
88 ![en-us_image_0000001174582848](figures/en-us_image_0000001174582848.png)
89