鸿蒙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)
  }
}
相关推荐
清霜之辰3 小时前
2025年如何实现安卓、iOS、鸿蒙跨平台开发
android·ios·跨平台·harmonyos
李坤3 小时前
如何在Mac搭建鸿蒙的ReactNative 开发环境
react native·ios·harmonyos
东林知识库4 小时前
鸿蒙NEXT开发-Navigation组件导航
华为·harmonyos
北京迅为5 小时前
【北京迅为】iTOP-RK3568OpenHarmony系统南向驱动开发-第2章 内核HDF驱动框架架构
华为·harmonyos·rk3568
小镇梦想家5 小时前
关于性能优化——Lazyforeach
harmonyos
北京迅为6 小时前
【北京迅为】iTOP-RK3568OpenHarmony系统南向驱动开发-第4章 UART基础知识
人工智能·嵌入式硬件·harmonyos·鸿蒙·rk3568
高心星9 小时前
HarmonyOS 5.0应用开发——鸿蒙接入高德地图实现POI搜索
华为·harmonyos·高德地图·harmonyos5.0·鸿蒙接入高德地图
Bruce_Liuxiaowei11 小时前
鸿蒙应用开发入门教程
华为·harmonyos
Dontla13 小时前
华为MindIE兼容OpenAI接口与兼容vLLM OpenAI接口的区别(华为VLLM)
华为