鸿蒙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)
  }
}
相关推荐
C雨后彩虹1 分钟前
猴子爬山问题
java·数据结构·算法·华为·面试
想你依然心痛10 分钟前
HarmonyOS 6(API 23)实战:基于悬浮导航、沉浸光感与Face AR & Body AR的“灵境直播间“——PC端沉浸式AR电商直播工作台
华为·ar·harmonyos·悬浮导航·沉浸光感
枫叶丹429 分钟前
【HarmonyOS 6.0】Desktop Extension Kit 正式接棒原状态栏服务,API 引用路径全面更新
开发语言·华为·harmonyos
前端不太难2 小时前
鸿蒙 App 的 Task 架构设计
华为·状态模式·harmonyos
HwJack2011 小时前
HarmonyOS APP开发之解密 ArkTS 状态管理:@State, @Observed, @ObjectLink 三角阵
华为·harmonyos
若兰幽竹19 小时前
【HarmonyOS 6.1 全场景实战】《灵犀厨房》实战(三):ArkTS 高效开发:TypeScript 核心与 API 23 新规
harmonyos·鸿蒙系统·harmonyos6.1.0
Swift社区19 小时前
鸿蒙 PC 为什么更像“系统”,而不是“应用平台”?
华为·harmonyos
aqi0021 小时前
一文速览 HarmonyOS 6.0.1 引入的十个新特性
android·华为·harmonyos·鸿蒙·harmony
麟听科技1 天前
HarmonyOS 6.0+ 跨端智能写作助手开发实战:多设备接续编辑与AI辅助创作落地
人工智能·分布式·华为·harmonyos·ai写作
求学中--1 天前
ArkUI电商首页完整实战
华为·typescript·harmonyos