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


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


## Required Permissions
Z
zengyawen 已提交
9 10

None
Z
zengyawen 已提交
11

Z
zengyawen 已提交
12 13 14 15 16 17

## APIs

RotationGesture(options?: { fingers?: number, angle?: number })

- Parameters
E
esterzhou 已提交
18
    | Name | Type | Mandatory | Default Value | Description | 
Z
zengyawen 已提交
19
  | -------- | -------- | -------- | -------- | -------- |
E
esterzhou 已提交
20 21
  | fingers | number | No | 2 | Minimum number of fingers to trigger a rotation. The value ranges from 2 to 5. | 
  | angle | number | No | 1.0 | Minimum degree that can trigger the rotation gesture. | 
Z
zengyawen 已提交
22 23 24 25 26 27


## Events

  | Name | Description | 
| -------- | -------- |
E
esterzhou 已提交
28 29 30 31
| onActionStart((event?: RotationGestureEvent) => void) | Callback invoked when a rotation gesture is recognized. | 
| onActionUpdate((event?: RotationGestureEvent) => void) | Callback invoked during the movement of the rotation gesture. | 
| onActionEnd((event?: RotationGestureEvent) => void) | Callback invoked when the finger used for the rotation gesture is lift. | 
| onActionCancel(event: () => void) | Callback invoked when a tap cancellation event is received after the rotation gesture is recognized. | 
Z
zengyawen 已提交
32 33 34 35

- RotationGestureEvent<sup>8+</sup> attributes
    | Name | Type | Description | 
  | -------- | -------- | -------- |
E
esterzhou 已提交
36
  | angle | number | Rotation angle. | 
Z
zengyawen 已提交
37 38 39 40


## Example

Z
zengyawen 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

```
@Entry
@Component
struct RotationGestureExample {
  @State angle: number = 0

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
      Text('RotationGesture angle:' + this.angle)
    }
    .height(100).width(200).padding(20).border({ width:1 })
    .margin(80).rotate({ x:1, y:2, z:3, angle: this.angle })
    .gesture(
      RotationGesture()
Z
zengyawen 已提交
56
        .onActionStart((event: RotationGestureEvent) => {
Z
zengyawen 已提交
57 58
          console.log('Rotation start')
        })
Z
zengyawen 已提交
59
        .onActionUpdate((event: RotationGestureEvent) => {
Z
zengyawen 已提交
60 61 62 63 64 65 66 67 68 69
          this.angle = event.angle
        })
        .onActionEnd(() => {
          console.log('Rotation end')
        })
    )
  }
}
```

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