鸿蒙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)
  }
}
相关推荐
leon_teacher1 小时前
HarmonyOS 6 ArkUI V2 实战:水墨启动页的 3 段错峰入场动画与 setInterval 进度条
华为·harmonyos
心疼你的一切2 小时前
从零到一:鸿蒙健康监测应用的全流程开发实录
人工智能·华为·harmonyos·鸿蒙·鸿蒙系统
想你依然心痛2 小时前
HarmonyOS 6(API 23)实战:基于Face AR情绪反馈与Body AR手势操控的“光影剪辑台“——PC端沉浸式影视后期系统
华为·ar·harmonyos·悬浮导航·沉浸光感
leon_teacher2 小时前
HarmonyOS 6 Navigation 实战:NavPathStack 路由架构与 onShown 跨页状态同步方案
华为·架构·harmonyos
号码认证服务2 小时前
企业固话号码认证能覆盖哪些手机品牌?支持华为、小米、OPPO、vivo等机型
服务器·网络·经验分享·python·华为·智能手机·云计算
云水一下3 小时前
下一代防火墙(NGFW)完全解析:从入门到华为eNSP模拟器实战
网络·华为·下一代防火墙
KKei16383 小时前
Flutter for OpenHarmony 编程技能树APP技术文章
flutter·华为·harmonyos
想你依然心痛3 小时前
HarmonyOS 6(API 23)实战:基于Face AR呼吸监测与Body AR姿态引导的“静界空间“——PC端沉浸式冥想疗愈系统
华为·ar·harmonyos·悬浮导航·沉浸光感
KKei16383 小时前
Flutter for OpenHarmony 个人财务管理与记账APP
flutter·华为·harmonyos
nashane3 小时前
HarmonyOS 6学习:Web组件与JavaScript交互的三大高频问题与终极解决方案
前端·学习·harmonyos