鸿蒙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)
  }
}
相关推荐
Easonmax1 小时前
基础入门 React Native 鸿蒙跨平台开发:实现面包屑导航
react native·react.js·harmonyos
Easonmax1 小时前
基础入门 React Native 鸿蒙跨平台开发:冒泡排序动画可视化
react native·react.js·harmonyos
鸣弦artha3 小时前
Flutter框架跨平台鸿蒙开发——GridView数据绑定实战
flutter·华为·harmonyos
zhujian826375 小时前
三十、【鸿蒙 NEXT】实现吸顶效果
harmonyos·鸿蒙·next·吸顶·吸顶效果·nestedscroll
C雨后彩虹5 小时前
优雅子数组
java·数据结构·算法·华为·面试
无穷小亮6 小时前
Flutter框架跨平台鸿蒙开发——育儿知识APP的开发流程
flutter·华为·harmonyos·鸿蒙
晚霞的不甘8 小时前
Flutter for OpenHarmony 引力弹球游戏开发全解析:从零构建一个交互式物理小游戏
前端·flutter·云原生·前端框架·游戏引擎·harmonyos·骨骼绑定
[H*]9 小时前
Positioned高级定位技巧
flutter·华为·harmonyos
倾国倾城的反派修仙者9 小时前
鸿蒙开发——使用弹窗授权保存媒体库资源
开发语言·前端·华为·harmonyos