1# SwipeGesture 2 3用于触发滑动事件,滑动速度大于100vp/s时可识别成功。 4 5> **说明:** 6> 7> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8 9 10## 接口 11 12SwipeGesture(value?: { fingers?: number, direction?: SwipeDirection, speed?: number }) 13 14**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 15 16**参数:** 17 18| 参数名称 | 参数类型 | 必填 | 参数描述 | 19| -------- | -------- | -------- | -------- | 20| fingers | number | 否 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。<br/>默认值:1 | 21| direction | [SwipeDirection](#swipedirection枚举说明) | 否 | 触发滑动手势的滑动方向。<br/>默认值:SwipeDirection.All | 22| speed | number | 否 | 识别滑动的最小速度。<br/>默认值:100VP/s <br/>**说明:** <br/>当滑动速度的值小于等于0时,会被转化为默认值。 | 23| isFingerCountLimited<sup>15+</sup> | boolean | 否 | 是否检查触摸屏幕的手指数量。如果触摸手指的数量不等于设置的触发滑动的最少手指数(即上述fingers参数),手势识别将失败。<br>默认值:false。| 24 25## SwipeDirection枚举说明 26 27**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 28 29| 名称 | 描述 | 30| -------- | -------- | 31| All | 所有方向。 | 32| Horizontal | 水平方向,手指滑动方向与x轴夹角小于45度时触发。 | 33| Vertical | 竖直方向,手指滑动方向与y轴夹角小于45度时触发。 | 34| None | 任何方向均不可触发。 | 35 36 37## 事件 38 39| 名称 | 功能描述 | 40| -------- | -------- | 41| onAction(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent对象说明)) => void) | Swipe手势识别成功回调。 <br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 42 43## 属性 44 45| 名称 | 类型 |描述 | 46| ---- | ------ | ---------------------------------------- | 47| tag<sup>11+</sup> | string | 设置Swipe手势标志,用于自定义手势判定时区分绑定的手势。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 48| allowedTypes<sup>14+</sup> | Array\<[SourceTool](ts-gesture-settings.md#sourcetool枚举说明9)> | 设置Swipe手势支持的事件输入源。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 49 50## 示例 51 52该示例通过配置SwipeGesture实现了滑动手势的识别。 53 54```ts 55// xxx.ets 56@Entry 57@Component 58struct SwipeGestureExample { 59 @State rotateAngle: number = 0 60 @State speed: number = 1 61 62 build() { 63 Column() { 64 Column() { 65 Text("SwipeGesture speed\n" + this.speed) 66 Text("SwipeGesture angle\n" + this.rotateAngle) 67 } 68 .border({ width: 3 }) 69 .width(300) 70 .height(200) 71 .margin(100) 72 .rotate({ angle: this.rotateAngle }) 73 // 单指竖直方向滑动时触发该事件 74 .gesture( 75 SwipeGesture({ direction: SwipeDirection.Vertical }) 76 .onAction((event: GestureEvent) => { 77 if (event) { 78 this.speed = event.speed 79 this.rotateAngle = event.angle 80 } 81 }) 82 ) 83 }.width('100%') 84 } 85} 86``` 87 88 