harmony 鸿蒙RotationGesture

  • 2022-08-09
  • 浏览 (522)

RotationGesture

用于触发旋转手势事件,触发旋转手势的最少手指为2指,最大为5指,最小改变度数为1度。

说明:

从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

接口

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

参数:

参数名称 参数类型 必填 参数描述
fingers number 触发旋转的最少手指数, 最小为2指,最大为5指。
默认值:2
angle number 触发旋转手势的最小改变度数,单位为deg。
默认值:1
说明:
当改变度数的值小于等于0时,会被转化为默认值。

事件

名称 功能描述
onActionStart(event:(event?: GestureEvent) => void) Rotation手势识别成功回调。
onActionUpdate(event:(event?: GestureEvent) => void) Rotation手势移动过程中回调。
onActionEnd(event:(event?: GestureEvent) => void) Rotation手势识别成功,手指抬起后触发回调。
onActionCancel(event: () => void) Rotation手势识别成功,接收到触摸取消事件触发回调。

示例

// xxx.ets
@Entry
@Component
struct RotationGestureExample {
  @State angle: number = 0
  @State rotateValue: number = 0

  build() {
    Column() {
      Column() {
        Text('RotationGesture angle:' + this.angle)
      }
      .height(200)
      .width(300)
      .padding(20)
      .border({ width: 3 })
      .margin(80)
      .rotate({ angle: this.angle })
      // 双指旋转触发该手势事件
      .gesture(
      RotationGesture()
        .onActionStart((event?: GestureEvent) => {
          console.info('Rotation start')
        })
        .onActionUpdate((event?: GestureEvent) => {
          if (event) {
            this.angle = this.rotateValue + event.angle
          }
        })
        .onActionEnd(() => {
          this.rotateValue = this.angle
          console.info('Rotation end')
        })
      )
    }.width('100%')
  }
}

zh-cn_image_0000001174264372

你可能感兴趣的鸿蒙文章

harmony 鸿蒙基于ArkTS的声明式开发范式

harmony 鸿蒙@ohos.arkui.advanced.Counter(计数器组件)

harmony 鸿蒙@ohos.arkui.advanced.SegmentButton(分段按钮)

harmony 鸿蒙@ohos.multimedia.avCastPicker (投播组件)

harmony 鸿蒙属性动画

harmony 鸿蒙枚举说明

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

0  赞