鸿蒙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)
  }
}
相关推荐
互联网散修9 小时前
鸿蒙星闪实战:从零构建跨设备文件传输——拆解文件传输数据流
华为·harmonyos
南村群童欺我老无力.9 小时前
鸿蒙PC - 资源文件引用路径的隐蔽陷阱
华为·harmonyos
南村群童欺我老无力.10 小时前
鸿蒙PC开发的Scroll组件maxHeight属性不存在
华为·harmonyos
Swift社区13 小时前
鸿蒙游戏多设备发布流程详解
游戏·华为·harmonyos
以太浮标14 小时前
华为eNSP模拟器综合实验之- 主机没有配置缺省网关时,通过路由式Proxy ARP实现通信(arp-proxy enable)
运维·网络·网络协议·华为·智能路由器·信息与通信
Goway_Hui16 小时前
【ReactNative鸿蒙化-三方库使用与C-API集成】
c语言·react native·harmonyos
nashane16 小时前
HarmonyOS 6.0 分布式相机实战:调用远端设备摄像头与AI场景识别(API 11+)
分布式·数码相机·harmonyos·harmonyos 5
Huanzhi_Lin17 小时前
鸿蒙NEXT出包
华为·harmonyos·鸿蒙·harmony·鸿蒙next·hap
luoganttcc17 小时前
华为昇腾(Ascend)等芯片,同样存在“寄存器 / 片上存储资源限制并发”的问题
算法·华为
╰つ栺尖篴夢ゞ18 小时前
HarmonyOS Next面试题之主线程与子线程访问同一个单例,获取的对象是同一个吗?
单例模式·多线程·harmonyos·sendable·actor模型·内存隔离