鸿蒙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)
  }
}
相关推荐
国服第二切图仔1 天前
鸿蒙应用开发之实现键值型数据库跨设备数据同步
数据库·wpf·harmonyos
默 语1 天前
Electron 应用中的系统检测方案对比与鸿蒙适配实践
javascript·electron·harmonyos·gwo
竹君子1 天前
研发管理知识库(4)华为研发管理流程简介
华为
ifeng09181 天前
HarmonyOS资源加载进阶:惰性加载、预加载与缓存机制
深度学习·缓存·harmonyos
爱笑的眼睛112 天前
HarmonyOS列表项滑动操作深度解析:从基础实现到高级交互
华为·harmonyos
ifeng09182 天前
HarmonyOS状态管理精细化:控制渲染范围与变量拆分策略
华为·harmonyos
智能与未来2 天前
华为芯片、OS、DB和技术平台等全面开源,MetaERP天然底座优势
华为·业界资讯
若安程序开发2 天前
web华为商城前端项目4页面
前端·华为
万少2 天前
记第一次鸿蒙应用上架之旅:一场略带遗憾的旅途
前端·harmonyos
HarmonyOS_SDK2 天前
【FAQ】HarmonyOS SDK 闭源开放能力 — Network Kit
harmonyos