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

E
ester.zhou 已提交
3
**RotationGesture** is used to trigger a rotation gesture, which requires two to five fingers with a minimum 1-degree rotation angle.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
>  **NOTE**
>
>  This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10 11

## APIs

E
ester.zhou 已提交
12 13 14
RotationGesture(value?: { fingers?: number, angle?: number })

**Parameters**
Z
zengyawen 已提交
15

E
ester.zhou 已提交
16 17 18 19
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fingers | number | No| Minimum number of fingers to trigger a rotation. The value ranges from 2 to 5.<br>Default value: **2**|
| angle | number | No| Minimum degree that can trigger the rotation gesture.<br>Default value: **1.0**|
Z
zengyawen 已提交
20 21 22 23


## Events

E
ester.zhou 已提交
24
| Parameter| Description|
Z
zengyawen 已提交
25
| -------- | -------- |
E
ester.zhou 已提交
26 27 28 29
| onActionStart(event:(event?: [GestureEvent](ts-gesture-settings.md)) =&gt; void) | Triggered when a rotation gesture is recognized.|
| onActionUpdate(event:(event?: [GestureEvent](ts-gesture-settings.md)) =&gt; void) | Triggered when the user moves the finger in a rotation gesture on the screen.|
| onActionEnd(event:(event?: [GestureEvent](ts-gesture-settings.md)) =&gt; void) | Triggered when the finger used for the rotation gesture is lift.|
| onActionCancel(event: () =&gt; void) | Triggered when a tap cancellation event is received after the rotation gesture is recognized.|
Z
zengyawen 已提交
30 31 32 33


## Example

E
ester.zhou 已提交
34 35
```ts
// xxx.ets
Z
zengyawen 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48
@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()
E
ester.zhou 已提交
49
        .onActionStart((event: GestureEvent) => {
Z
zengyawen 已提交
50 51
          console.log('Rotation start')
        })
E
ester.zhou 已提交
52
        .onActionUpdate((event: GestureEvent) => {
Z
zengyawen 已提交
53 54 55 56 57 58 59 60 61 62
          this.angle = event.angle
        })
        .onActionEnd(() => {
          console.log('Rotation end')
        })
    )
  }
}
```

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