鸿蒙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)
  }
}
相关推荐
前端不太难2 分钟前
鸿蒙 App 重构:如何从混乱到清晰?
重构·状态模式·harmonyos
听麟15 小时前
HarmonyOS 6.0+ PC端离线翻译工具开发实战:端侧AI模型集成与多格式内容翻译落地
人工智能·华为·harmonyos
南村群童欺我老无力.15 小时前
鸿蒙pc中权限申请流程与用户拒绝处理
华为·harmonyos
@不误正业15 小时前
AI-Agent安全性实战-提示注入防御与工具调用沙箱隔离
人工智能·华为·harmonyos
南村群童欺我老无力.19 小时前
鸿蒙PC多端适配的断点设计与布局策略
华为·harmonyos
轻口味20 小时前
HarmonyOS 6.1 全栈实战录 - 04 镜像世界:Spatial Recon Kit 3D空间重建与企业级高精度建模实战
3d·华为·harmonyos
酿情师20 小时前
2026平航杯倩倩手机逆向包逆向全过程(逆向鸿蒙系统app包)
华为·智能手机·harmonyos·逆向·ctf·re·取证
南村群童欺我老无力.20 小时前
鸿蒙PC DevEco Studio调试器的使用技巧与局限
华为·harmonyos