ts-basic-gestures-swipegesture.md 2.2 KB
Newer Older
Z
zengyawen 已提交
1
# SwipeGesture
Z
zengyawen 已提交
2 3


Z
zengyawen 已提交
4 5 6 7 8
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:**
> This gesture is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.


## Required Permissions
Z
zengyawen 已提交
9 10 11

None

Z
zengyawen 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

## APIs

SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: number })

- Parameters
    | Name | Type | Mandatory | Default Value | Description | 
  | -------- | -------- | -------- | -------- | -------- |
  | fingers | number | No | 1 | Minimum number of fingers to trigger a swipe gesture. The value ranges from 1 to 10. | 
  | direction | SwipeDirection | No | SwipeDirection.All | Swipe direction. | 
  | speed | number | No | 100 | Minimum speed of the swipe gesture (100 vp/s). | 

- SwipeDirection enums
    | Name | Description | 
  | -------- | -------- |
  | All | All directions. | 
  | Horizontal | Horizontal direction. | 
  | Vertical | Vertical direction. | 


## Events

  | Name | Description | 
| -------- | -------- |
| onAction(callback:(event?: SwipeGestureEvent) => void) | Callback invoked when a swipe gesture is recognized. | 


- SwipeGestureEvent attributes
    | Name | Type | Description | 
  | -------- | -------- | -------- |
  | angle | number | Angle of the swipe gesture. | 
  | speed | number | Speed of the swipe gesture. | 


## Example

Z
zengyawen 已提交
48 49 50 51 52 53 54 55 56 57

```
@Entry
@Component
struct SwipeGestureExample {
  @State rotateAngle : number = 0
  @State speed : number = 1

  build() {
    Column() {
Z
zengyawen 已提交
58 59
      Text("SwipGesture speed : " + this.speed)
      Text("SwipGesture angle : " + this.rotateAngle)
Z
zengyawen 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    }
    .position({x: 80, y: 200})
    .border({width:2})
    .width(260).height(260)
    .rotate({x: 0, y: 0, z: 1, angle: this.rotateAngle})
    .gesture(
      SwipeGesture({fingers: 1, direction:SwipeDirection.Vertical})
        .onAction((event: SwipeGestureEvent) => {
          this.speed = event.speed
          this.rotateAngle = event.angle
      })
    )
  }
}
```

Z
zengyawen 已提交
76
![en-us_image_0000001257138365](figures/en-us_image_0000001257138365.gif)