鸿蒙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)
  }
}
相关推荐
l1t28 分钟前
在华为arm64 kylin计算机上安装docker编译llama.cpp的步骤
华为·docker·llama·kylin
是稻香啊3 小时前
HarmonyOS6 ArkUI 触摸拦截(onTouchIntercept)全面解析与实战演示
ubuntu·华为·harmonyos·harmonyos6
是稻香啊4 小时前
HarmonyOS6 ArkUI 子组件触摸测试控制(onChildTouchTest)全面解析与实战演示
华为·harmonyos·harmonyos6
fei_sun6 小时前
【鸿蒙智能硬件】(一)环境配置
华为·harmonyos
大雷神7 小时前
HarmonyOS APP<玩转React>开源教程一:开发环境搭建与项目创建
harmonyos
HarmonyOS_SDK7 小时前
高德地图携手HamonyOS SDK,首发鸿蒙AR实景步导
harmonyos
●VON12 小时前
【鸿蒙PC】在 HarmonyOS 上跑 Electron?手把手教你搞定桌面欢迎页!(Mac版)
开发语言·macos·华为·electron·电脑·harmonyos
深念Y12 小时前
华为重启门自救记:从打火机“邪修”到入坑电子维修之路
华为·鸿蒙·硬件·电子·数码·维修·虚焊
前端不太难13 小时前
一个真实鸿蒙 App 的工程目录结构
华为·状态模式·harmonyos
枫叶丹413 小时前
【HarmonyOS 6.0】聚合链接(App Linking)实战:从创建配置到应用跳转
开发语言·华为·harmonyos