鸿蒙next 点击穿透实现

点击穿透可以参考华为开发的保留文章,该章节只能在developer preview版本下查看
点击穿透

主要的方法是hitTestBehavior

typescript 复制代码
// xxx.ets
@Entry
@Component
struct HitTestBehaviorExample {
  build() {
    // outer stack
    Stack() {
      Button('outer button')
        .onTouch((event) => {
          console.info('outer button touched type: ' + (event as TouchEvent).type)
        })
      // inner stack
      Stack() {
        Button('inner button')
          .onTouch((event) => {
            console.info('inner button touched type: ' + (event as TouchEvent).type)
          })
      }
      .width("100%").height("100%")
      .hitTestBehavior(HitTestMode.Block)
      .onTouch((event) => {
        console.info('stack touched type: ' + (event as TouchEvent).type)
      })

      Text('Transparent')
        .hitTestBehavior(HitTestMode.Transparent)
        .width("100%").height("100%")
        .onTouch((event) => {
          console.info('text touched type: ' + (event as TouchEvent).type)
        })
    }.width(300).height(300)
  }
}
相关推荐
阿林来了18 分钟前
Flutter三方库适配OpenHarmony【flutter_speech】— 原始插件源码分析
flutter·harmonyos·鸿蒙
不爱吃糖的程序媛20 分钟前
Flutter 应用退出插件 HarmonyOS 适配技术详解
flutter·华为·harmonyos
lqj_本人5 小时前
Flutter三方库适配OpenHarmony【apple_product_name】华为Pura系列设备映射表
flutter·华为
木斯佳6 小时前
HarmonyOS实战(解决方案篇)—深色模式适配完全指南:从原理到实践
华为·harmonyos
阿林来了8 小时前
Flutter三方库适配OpenHarmony【flutter_speech】— 语音识别停止与取消
flutter·语音识别·harmonyos
松叶似针9 小时前
Flutter三方库适配OpenHarmony【secure_application】— 应用生命周期回调注册
flutter·harmonyos
无巧不成书02189 小时前
【RN鸿蒙教学|第12课时】进阶实战+全流程复盘:痛点攻坚与实战项目初始化
react native·华为·开源·交互·harmonyos
键盘鼓手苏苏10 小时前
Flutter for OpenHarmony 实战:flutter_redux 全局状态机与单向数据流
flutter·华为·harmonyos
阿林来了11 小时前
Flutter三方库适配OpenHarmony【flutter_speech】— 麦克风权限申请实现
flutter·harmonyos
松叶似针12 小时前
Flutter三方库适配OpenHarmony【secure_application】— 窗口事件监听与应用切换检测
flutter·harmonyos