鸿蒙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)
  }
}
相关推荐
用户1179104883317 分钟前
AI输出满屏井号星号?hmharness把Markdown渲染成终端表格 GitHub:swsgbl/hmharness
ai编程·harmonyos
了一1232 小时前
鸿蒙ArkWeb 长截图(滚动截图)技术方案总结
harmonyos
熊猫钓鱼>_>3 小时前
平行视界兼容模式与魔法变量配置避坑【鸿蒙心迹】
运维·服务器·开发语言·笔记·华为·harmonyos·openharmony
李&@杰4 小时前
小型园区网从零到精通
网络·tcp/ip·华为
罗四强4 小时前
第2篇:环境搭建:DevEco Studio 安装 + 第一个 Hello World
harmonyos·鸿蒙·鸿蒙系统
用户117910488335 小时前
AI终端里复制不了代码?hmharness把鼠标还给终端 GitHub:swsgbl/hmharness
ai编程·harmonyos
贾伟康7 小时前
HarmonyOS 端侧智能体长对话压缩:摘要版本、证据索引与安全回退
harmonyos·arkts·状态恢复·上下文压缩·端侧智能体
NJPJI_Yang8 小时前
鸿蒙操作系统小艺 Skill 开发实战:让应用被 HarmonyOS 7 一句话召唤
pytorch·深度学习·harmonyos
redtank20009 小时前
纯血鸿蒙学习效率三件套实测:背单词艾宾浩斯曲线、时间记录与睡眠辅助
学习·华为·harmonyos
打工仔折腾 AI9 小时前
鸿蒙移动端直连 Windows 远程桌面配置与性能调优实践
人工智能·windows·后端·python·华为·性能优化·harmonyos