1# PinchGesture 2 3用于触发捏合手势,触发捏合手势的最少手指为2指,最大为5指,最小识别距离为5vp。 4 5> **说明:** 6> 7> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8 9 10## 接口 11 12PinchGesture(value?: { fingers?: number, distance?: number }) 13 14**参数:** 15 16| 参数名称 | 参数类型 | 必填 | 参数描述 | 17| -------- | -------- | -------- | -------- | 18| fingers | number | 否 | 触发捏合的最少手指数, 最小为2指,最大为5指。<br/>默认值:2 <br/>触发手势手指可以多于fingers数目,但只有先落下的与fingers相同数目的手指参与手势计算。 | 19| distance | number | 否 | 最小识别距离,单位为vp。<br/>默认值:5 <br/>**说明:** <br/> 当识别距离的值小于等于0时,会被转化为默认值。| 20 21 22## 事件 23 24| 名称 | 功能描述 | 25| -------- | -------- | 26| onActionStart(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent对象说明)) => void) | Pinch手势识别成功回调。 | 27| onActionUpdate(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent对象说明)) => void) | Pinch手势移动过程中回调。 | 28| onActionEnd(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent对象说明)) => void) | Pinch手势识别成功,手指抬起后触发回调。 | 29| onActionCancel(event: () => void) | Pinch手势识别成功,接收到触摸取消事件触发回调。<br/>**说明:** <br/>在窗口失焦的时候会触发。| 30 31## 属性 32 33| 名称 | 类型 |描述 | 34| ---- | ------ | ---------------------------------------- | 35| tag<sup>11+</sup> | string | 设置Pinch手势标志,用于自定义手势判定时区分绑定的手势。| 36 37## 示例 38 39```ts 40// xxx.ets 41@Entry 42@Component 43struct PinchGestureExample { 44 @State scaleValue: number = 1 45 @State pinchValue: number = 1 46 @State pinchX: number = 0 47 @State pinchY: number = 0 48 49 build() { 50 Column() { 51 Column() { 52 Text('PinchGesture scale:\n' + this.scaleValue) 53 Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')') 54 } 55 .height(200) 56 .width(300) 57 .padding(20) 58 .border({ width: 3 }) 59 .margin({ top: 100 }) 60 .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 }) 61 // 三指捏合触发该手势事件 62 .gesture( 63 PinchGesture({ fingers: 3 }) 64 .onActionStart((event: GestureEvent) => { 65 console.info('Pinch start') 66 }) 67 .onActionUpdate((event: GestureEvent) => { 68 if (event) { 69 this.scaleValue = this.pinchValue * event.scale 70 this.pinchX = event.pinchCenterX 71 this.pinchY = event.pinchCenterY 72 } 73 }) 74 .onActionEnd((event: GestureEvent) => { 75 this.pinchValue = this.scaleValue 76 console.info('Pinch end') 77 }) 78 ) 79 }.width('100%') 80 } 81} 82``` 83 84  85