鸿蒙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)
  }
}
相关推荐
威哥爱编程8 小时前
【鸿蒙开发案例篇】拒绝裸奔!鸿蒙6实现PDF动态加密
harmonyos·arkts·arkui
是Yu欸9 小时前
①【openFuyao】智算时代的异构算力连接器
华为·华为云·算力·openfuyao
yilan_n11 小时前
在Linux下使用Termony搭建HNP自验证环境全指南
linux·harmonyos·termony·hnp·命令行适配
志尊宝13 小时前
HarmonyOS ArkTS 入门(一)
华为·harmonyos
90后的晨仔13 小时前
🧩 一文搞懂 HarmonyOS 中的 HAP、HAR 和 HSP:它们到底是什么?怎么用?
harmonyos
m0_6855350814 小时前
光是如何产生的?
华为·光学·光学设计·光学工程·镜头设计
Simon席玉14 小时前
C++的命名重整
开发语言·c++·华为·harmonyos·arkts
我是Feri15 小时前
HarmonyOS 6.0 视频播放组件使用教程
华为·音视频·harmonyos
大土豆的bug记录17 小时前
鸿蒙权限授权弹窗(推荐)
华为·harmonyos
马剑威(威哥爱编程)17 小时前
【鸿蒙开发案例篇】基于MindSpore Lite的端侧人物图像分割案例
华为·harmonyos