鸿蒙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)
  }
}
相关推荐
Georgewu26 分钟前
【HarmonyOS】鸿蒙端云一体化开发入门详解 (一)
harmonyos
Georgewu26 分钟前
【HarmonyOS】Web 组件的 PDF 文档预览功能详解
harmonyos
Chen--Xing2 小时前
第一届OpenHarmonyCTF--Crypto--WriteUp
网络安全·密码学·harmonyos
HarmonyOS_SDK4 小时前
京东携手HarmonyOS SDK首发家电AR高精摆放功能
harmonyos
二二孚日4 小时前
自用华为ICT云赛道Big Data第六章知识点-分布式搜索服务ElasticSearch
大数据·华为
塞尔维亚大汉4 小时前
鸿蒙内核源码分析(根文件系统) | 先挂到/上的文件系统
源码·harmonyos
别说我什么都不会4 小时前
【OpenHarmony】鸿蒙开发之Checksum
harmonyos
Fanmeang5 小时前
OSPF路由过滤
运维·网络·华为·ip·路由·ospf·路由过滤
周胡杰6 小时前
鸿蒙arkts使用关系型数据库,使用DB Browser for SQLite连接和查看数据库数据?使用TaskPool进行频繁数据库操作
前端·数据库·华为·harmonyos·鸿蒙·鸿蒙系统
simple丶8 小时前
【HarmonyOS】封装用户鉴权工具类
harmonyos·arkts·arkui