HarmonyOS 鸿蒙Next 手势处理异常

HarmonyOS 鸿蒙Next 手势处理异常

我们有视频播放器场景,页面可以响应单击,双击、滑动手势

我在一个组件上同时设置了单击,双击,水平滑动。

发现双击和水平滑动时也会走单击的事件回调,这种感觉不符合

代码如下:

@Entry

@Component

struct Index {

  build() {

    Column() {

      Navigation() {

      }.toolbarConfiguration(this.NavigationToolbar)

    }

    .height('100%')

    .width('100%')

    .backgroundColor(Color.Gray)

    .gesture(GestureGroup(GestureMode.Parallel,

      TapGesture().onAction((event: GestureEvent | undefined) => {

        hilog.debug(0x00, 'IndexIndex', 'singleTap')

      }),

      TapGesture({ count: 2 }).onAction((event: GestureEvent | undefined) => {

        hilog.debug(0x00, 'IndexIndex', 'doubleTap')

      }),

      PanGesture({ direction: PanDirection.Horizontal })

        .onActionStart((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionStart')

        })

        .onActionUpdate((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionUpdate')

        })

        .onActionEnd((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionEnd')

        }))

    )

  }

  @Builder

  NavigationToolbar() {

    Row() {

      Column() {

        Image($r('app.media.startIcon')).width(24)

      }.layoutWeight(1)

      Column() {

        Image($r('app.media.startIcon')).width(24).scale({ x: 4, y: 4 })

      }.layoutWeight(1)

      Column() {

        Image($r('app.media.startIcon')).width(24)

      }.layoutWeight(1)

    }

    .height(34)

    .width('100%').backgroundColor(Color.White)

  }

}

更多关于HarmonyOS 鸿蒙Next 手势处理异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复
.gesture(GestureGroup(GestureMode.Parallel,
      TapGesture({ count: 2 }).onAction((event: GestureEvent | undefined) => {

        hilog.debug(0x00, 'IndexIndex', 'doubleTap')

      }),

      TapGesture().onAction((event: GestureEvent | undefined) => {

        hilog.debug(0x00, 'IndexIndex', 'singleTap')

      }),

      PanGesture({ direction: PanDirection.Horizontal })

        .onActionStart((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionStart')

        })

        .onActionUpdate((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionUpdate')

        })

        .onActionEnd((event: GestureEvent | undefined) => {

          hilog.debug(0x00, 'IndexIndex', 'onActionEnd')

        }))

    )

更多关于HarmonyOS 鸿蒙Next 手势处理异常的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


HarmonyOS 鸿蒙Next 手势处理异常通常涉及系统对手势识别的逻辑错误或资源冲突。在处理此类问题时,需确认以下几点:

  1. 手势定义与识别:检查代码中手势的定义是否与预期一致,包括手势类型、触发条件及响应动作。确保手势识别库版本与HarmonyOS版本兼容。

  2. 系统资源占用:分析系统日志,查看是否有其他进程或应用占用大量资源,导致手势处理延迟或失效。必要时,重启设备以释放资源。

  3. 权限配置:确认应用已获取必要的权限,如触控权限,以正确接收并处理手势输入。

  4. 系统更新:检查HarmonyOS系统是否为最新版本,旧版本可能包含未修复的手势处理bug。更新至最新版本可能解决该问题。

  5. 硬件兼容性:若问题出现在特定设备上,考虑硬件兼容性因素。尝试在其他设备上复现问题,以排除设备特定问题。

  6. 代码审查:对涉及手势处理的相关代码进行审查,确保逻辑正确,无死循环或异常处理不当的情况。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部