当前位置:   article > 正文

鸿蒙开发之组合手势_gesturegroup

gesturegroup

当我们需要支持多个手势的时候,可以通过GestureGroup来实现,如下实现了同时支持Tap和Pan手势

  1. import Prompt from '@system.prompt'
  2. @Entry
  3. @Component
  4. struct OfficialGestureGroupPage {
  5. @State message: string = 'Hello World'
  6. build() {
  7. Column() {
  8. Column() {
  9. Text(this.message)
  10. .fontSize(50)
  11. .fontWeight(FontWeight.Bold)
  12. .border({width:3})
  13. .backgroundColor(Color.Brown)
  14. }
  15. .width(300)
  16. .height(200)
  17. .margin(50)
  18. .padding(20)
  19. .gesture(
  20. //并发的触发所有手势
  21. GestureGroup(GestureMode.Parallel,
  22. //添加拖拽手势
  23. PanGesture()
  24. .onActionStart(() => {
  25. Prompt.showToast({message:'gesture pan start'})
  26. })
  27. .onActionUpdate((event:GestureEvent) => {
  28. Prompt.showToast({message:'gesture pan update'})
  29. })
  30. .onActionEnd(() => {
  31. Prompt.showToast({message:'gesture pan end'})
  32. }),
  33. //添加点击手势
  34. TapGesture()
  35. .onAction(() => {
  36. Prompt.showToast({message:'gesture tap'})
  37. })
  38. )
  39. )
  40. }
  41. .width('100%')
  42. .height('100%')
  43. }
  44. }

其中,GestureGroup的mode参数含义如下

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/300379
推荐阅读
相关标签
  

闽ICP备14008679号