鸿蒙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)
  }
}
相关推荐
特立独行的猫a7 分钟前
鸿蒙 PC 三方库移植实战 · 直播课件(详细教案)
华为·harmonyos·移植·鸿蒙pc·opendesk
xmdy58662 小时前
Flutter+开源鸿蒙实战|企业级工具APP Day2 全局网络封装与 Dio 拦截器实战(鸿蒙兼容版)
flutter·开源·harmonyos
xmdy58662 小时前
Flutter+开源鸿蒙实战:企业级工具类APP开发教程(含第三方库适配)
flutter·开源·harmonyos
richard_yuu2 小时前
鸿蒙Stage模型实战|心晴驿站分层架构与隐私安全设计
安全·架构·harmonyos
Swift社区3 小时前
Flutter / React / ArkUI:在鸿蒙 PC 上怎么选?
flutter·react.js·harmonyos
ZHW_AI课题组3 小时前
调用华为智能云API实现手写图片识别
图像处理·python·机器学习·华为·分类
leon_teacher3 小时前
HarmonyOS 6 鸿蒙APP应用实战:基于 ArkUI V2 打造儿童古诗学习宝 App 从 0 到 1
学习·华为·harmonyos
想你依然心痛4 小时前
HarmonyOS 6(API 23)实战:基于Face AR数字人驱动与Body AR手势控制的“星播工坊“——PC端沉浸式虚拟直播系统
华为·ar·harmonyos·悬浮导航·沉浸光感
哦***74 小时前
真实评测 | FreeBuds Pro 5独立空间音频
华为·音频·harmonyos
前端不太难5 小时前
一个电商鸿蒙 App 的架构设计实战
华为·状态模式·harmonyos