鸿蒙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)
  }
}
相关推荐
xmdy586610 分钟前
Flutter + 开源鸿蒙实战|城市智慧停车管理系统 Day1 项目初始化+架构搭建+全局依赖集成+多端适配基座
flutter·开源·harmonyos
wqdian_com1 小时前
华为手机浏览器的一个bug
服务器·华为·bug
轻口味1 小时前
HarmonyOS 6.1 全栈实战录 - 06 状态定力:PersistenceV2 深度进阶与集合类型持久化实战
华为·harmonyos
key_3_feng1 小时前
鸿蒙音乐播放器应用开发指南
华为·harmonyos
大雷神1 小时前
HarmonyOS APP<<古今职鉴定>>开源教程第2篇:开发环境搭建:DevEco Studio 全攻略
华为·华为云·harmonyos
Swift社区1 小时前
鸿蒙 PC 多窗口系统:一次讲透实现原理
华为·harmonyos
xmdy58661 小时前
Flutter + 开源鸿蒙实战|城市智慧停车管理系统 Day3 车场详情+车位预约+计时计费算法+路线导航+常用车场缓存持久化
flutter·开源·harmonyos
xmdy58662 小时前
Flutter+开源鸿蒙实战|城市共享驿站智能存取系统 Day6 全局UI精细化美化+通用组件封装+反馈设置模块+隐私弹窗+鸿蒙打包签名适配+项目整体重构
flutter·开源·harmonyos
三声三视2 小时前
Electron+鸿蒙桌面应用实战:跨平台开发完全指南
electron·harmonyos·鸿蒙·桌面
求学中--2 小时前
鸿蒙实战:用状态管理实现一个完整的Todo应用,从@State到@Provide全链路打通
华为·harmonyos·组件化开发·完整项目