HarmonyOS应用API手势方法-SwipeGesture

描述:用于触发滑动事件,滑动最小速度为100vp/s时识别成功。

Api:从API Version 8开始支持

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

参数:

HarmonyOS应用API手势方法-SwipeGesture_第1张图片

SwipeDirection枚举:

HarmonyOS应用API手势方法-SwipeGesture_第2张图片


事件:

HarmonyOS应用API手势方法-SwipeGesture_第3张图片


示例代码:

  • @Entry
    @Component
    struct SwipeGestureExample {
      @State rotateAngle: number = 0;
      @State speed: number = 1;
    
      build() {
        Column() {
          Column() {
            Text("SwipeGesture speed\n" + this.speed).fontSize(20)
            Text("SwipeGesture angle\n" + this.rotateAngle).fontSize(20)
          }
          .border({ width: 3 })
          .width(300)
          .height(200)
          .margin(100)
          .rotate({ angle: this.rotateAngle })
          // 单指竖直方向滑动时触发该事件
          .gesture(
          SwipeGesture({ direction: SwipeDirection.Vertical })
            .onAction((event: GestureEvent) => {
              this.speed = event.speed;
              this.rotateAngle = event.angle;
            })
          )
        }.width('100%')
      }
    }

示例效果:

HarmonyOS应用API手势方法-SwipeGesture_第4张图片


代码地址:(HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com)

你可能感兴趣的:(harmonyos)