#盲盒+码#HarmonyOS应用API手势方法-SwipeGesture

鸿蒙时代
发布于 2022-12-1 14:57
浏览
0收藏

【本文正在参加「盲盒」+码有奖征文活动】(https://ost.51cto.com/posts/19288)
描述:用于触发滑动事件,滑动最小速度为100vp/s时识别成功。

Api:从API Version 8开始支持

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

参数:
#盲盒+码#HarmonyOS应用API手势方法-SwipeGesture-鸿蒙开发者社区

SwipeDirection枚举:

#盲盒+码#HarmonyOS应用API手势方法-SwipeGesture-鸿蒙开发者社区
事件:

#盲盒+码#HarmonyOS应用API手势方法-SwipeGesture-鸿蒙开发者社区
示例代码:

@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%')
  }
}

  • 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.

示例效果:
#盲盒+码#HarmonyOS应用API手势方法-SwipeGesture-鸿蒙开发者社区
代码地址:(https://gitee.com/jltfcloudcn/jump_to/tree/master/TapGesture)

标签
SwipeGesture.docx 34.23K 17次下载
已于2022-12-1 17:34:45修改
2
收藏
回复
举报
2


回复
    相关推荐