• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SwipeGesture
2
3>  **说明:**
4>  从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
5
6
7## 接口
8
9SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: number })
10
11**参数:**
12
13| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
14| -------- | -------- | -------- | -------- | -------- |
15| fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 |
16| direction | [SwipeDirection](#swipedirection枚举说明) | 否 | SwipeDirection.All | 触发滑动手势的滑动方向。 |
17| speed | number | 否 | 100 | 识别滑动的最小速度(默认为100vp/秒)。 |
18
19## SwipeDirection枚举说明
20
21| 名称 | 描述 |
22| -------- | -------- |
23| All | 所有方向。 |
24| Horizontal | 水平方向。 |
25| Vertical | 竖直方向。 |
26| None | 任何方向均不可触发。 |
27
28
29## 事件
30
31| 名称 | 功能描述 |
32| -------- | -------- |
33| onAction(event:(event?: [GestureEvent](ts-gesture-settings.md)) => void) | 滑动手势识别成功回调。 |
34
35## 示例
36
37```ts
38// xxx.ets
39@Entry
40@Component
41struct SwipeGestureExample {
42  @State rotateAngle: number = 0;
43  @State speed: number = 1;
44
45  build() {
46    Column() {
47      Column() {
48        Text("SwipeGesture speed\n" + this.speed)
49        Text("SwipeGesture angle\n" + this.rotateAngle)
50      }
51      .border({ width: 3 })
52      .width(300)
53      .height(200)
54      .margin(100)
55      .rotate({ z: 1, angle: this.rotateAngle })
56      // 单指竖直方向滑动时触发该事件
57      .gesture(
58      SwipeGesture({ direction: SwipeDirection.Vertical })
59        .onAction((event: GestureEvent) => {
60          this.speed = event.speed;
61          this.rotateAngle = event.angle;
62        })
63      )
64    }.width('100%')
65  }
66}
67```
68
69![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374559.png)
70