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