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 24## SwipeDirection枚举说明 25 26**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 27 28| 名称 | 描述 | 29| -------- | -------- | 30| All | 所有方向。 | 31| Horizontal | 水平方向,手指滑动方向与x轴夹角小于45度时触发。 | 32| Vertical | 竖直方向,手指滑动方向与y轴夹角小于45度时触发。 | 33| None | 任何方向均不可触发。 | 34 35 36## 事件 37 38| 名称 | 功能描述 | 39| -------- | -------- | 40| onAction(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent对象说明)) => void) | Swipe手势识别成功回调。 <br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 41 42## 属性 43 44**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 45 46| 名称 | 类型 |描述 | 47| ---- | ------ | ---------------------------------------- | 48| tag<sup>11+</sup> | string | 设置Swipe手势标志,用于自定义手势判定时区分绑定的手势。| 49 50## 示例 51 52```ts 53// xxx.ets 54@Entry 55@Component 56struct SwipeGestureExample { 57 @State rotateAngle: number = 0 58 @State speed: number = 1 59 60 build() { 61 Column() { 62 Column() { 63 Text("SwipeGesture speed\n" + this.speed) 64 Text("SwipeGesture angle\n" + this.rotateAngle) 65 } 66 .border({ width: 3 }) 67 .width(300) 68 .height(200) 69 .margin(100) 70 .rotate({ angle: this.rotateAngle }) 71 // 单指竖直方向滑动时触发该事件 72 .gesture( 73 SwipeGesture({ direction: SwipeDirection.Vertical }) 74 .onAction((event: GestureEvent) => { 75 if (event) { 76 this.speed = event.speed 77 this.rotateAngle = event.angle 78 } 79 }) 80 ) 81 }.width('100%') 82 } 83} 84``` 85 86 