#在HarmonyOS星河遨游# HarmonyOS应用API手势方法-PinchGesture

计算机编程小强
发布于 2024-8-16 10:35
浏览
0收藏

描述:用于触发捏合手势,触发捏合手势的最少手指为2指,最大为5指,最小识别距离为3vp。

Api:从API Version 7开始支持

接口:PinchGesture(value?: { fingers?: number, distance?: number })

参数:

#在HarmonyOS星河遨游# HarmonyOS应用API手势方法-PinchGesture-鸿蒙开发者社区

事件:

#在HarmonyOS星河遨游# HarmonyOS应用API手势方法-PinchGesture-鸿蒙开发者社区

示例代码:

@Entry
@Component
struct PinchGestureExample {
  @State scaleValue: number = 1;
  @State pinchValue: number = 1;
  @State pinchX: number = 0;
  @State pinchY: number = 0;

  build() {
    Column() {
      Column() {
        Text('PinchGesture scale:\n' + this.scaleValue).fontSize(20)
        Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')').fontSize(20)
      }
      .height(300)
      .width(300)
      .padding(20)
      .border({ width: 3 })
      .margin({ top: 100 })
      .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
      // 三指捏合触发该手势事件
      .gesture(
      PinchGesture({ fingers: 3 })
        .onActionStart((event: GestureEvent) => {
          console.info('Pinch start');
        })
        .onActionUpdate((event: GestureEvent) => {
          this.scaleValue = this.pinchValue * event.scale;
          this.pinchX = event.pinchCenterX;
          this.pinchY = event.pinchCenterY;
        })
        .onActionEnd(() => {
          this.pinchValue = this.scaleValue;
          console.info('Pinch end');
        })
      )
    }.width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 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.

示例效果

#在HarmonyOS星河遨游# HarmonyOS应用API手势方法-PinchGesture-鸿蒙开发者社区


代码地址:

(​​https://gitee.com/jltfcloudcn/jump_to/tree/master/TapGesture​​)

已于2024-8-16 10:35:31修改
收藏
回复
举报


回复
    相关推荐