HarmonyOS 鸿蒙Next bindContentCover能设置hitTestBehavior吗
HarmonyOS 鸿蒙Next bindContentCover能设置hitTestBehavior吗
modalTransition: ModalTransition.NONE,
backgroundColor: Color.Transparent,
自定义了UI,UI没有挡着b,现在想实现点击b就关闭bindContentCover。
设置了.hitTestBehavior(HitTestMode.Transparent)后,还是需要关闭C,b才能响应点击事件
更多关于HarmonyOS 鸿蒙Next bindContentCover能设置hitTestBehavior吗的实战教程也可以访问 https://www.itying.com/category-93-b0.html
边有一个弹框遮罩穿透的案列您可以参考一下,看下能否满足需求
[@Entry](/user/Entry)
[@Component](/user/Component)
struct DDD {
[@State](/user/State) message: string = 'Hello World';
[@State](/user/State) visible: Visibility = Visibility.None
[@State](/user/State) isShow: boolean = false
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
build() {
Column() {
Button(‘打开弹窗’).onClick(() => {
this.visible = Visibility.Visible
})
Button(‘关闭弹窗’).onClick(() => {
this.visible = Visibility.None
})
Column()
.width(<span class="hljs-string">'100%'</span>)
.height(<span class="hljs-string">'100%'</span>)
.position({ x: <span class="hljs-number">0</span>, y: <span class="hljs-number">0</span> })
.zIndex(<span class="hljs-number">10</span>)
.backgroundColor(<span class="hljs-number">0x33000000</span>)
.visibility(<span class="hljs-keyword">this</span>.visible)
.hitTestBehavior(HitTestMode.None)
Stack() {
Flex({
direction: FlexDirection.Column,
alignContent: FlexAlign.Center,
justifyContent: FlexAlign.SpaceEvenly,
alignItems: ItemAlign.Center
}) {
Text(<span class="hljs-string">"这是个可以穿透的弹窗"</span>)
.fontColor(Color.Blue)
.fontSize(<span class="hljs-number">18</span>)
.onClick(() => {
console.info(<span class="hljs-string">"测试测试测试"</span>)
})
.hitTestBehavior(HitTestMode.None)
.visibility(<span class="hljs-keyword">this</span>.visible)
.zIndex(<span class="hljs-number">13</span>)
Row({ space: <span class="hljs-number">10</span> }) {
Button(<span class="hljs-string">"确定"</span>)
.onClick(() => {
<span class="hljs-keyword">this</span>.visible = Visibility.Hidden
})
.visibility(<span class="hljs-keyword">this</span>.visible)
Button(<span class="hljs-string">"取消"</span>)
.onClick(() => {
<span class="hljs-keyword">this</span>.visible = Visibility.Hidden
})
.visibility(<span class="hljs-keyword">this</span>.visible)
}
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.Center)
.width(<span class="hljs-string">"100%"</span>)
}
.border({ radius: <span class="hljs-number">25</span> })
.visibility(<span class="hljs-keyword">this</span>.visible)
<span class="hljs-comment">// .backgroundColor(Color.Green)//#00000000</span>
.hitTestBehavior(HitTestMode.None)
.height(<span class="hljs-number">110</span>)
.width(<span class="hljs-number">220</span>)
.zIndex(<span class="hljs-number">12</span>)
List() {
ForEach(<span class="hljs-keyword">this</span>.arr, (item: number) => {
ListItem() {
Row() {
Text(<span class="hljs-string">'文本'</span>)
}.justifyContent(FlexAlign.Center).width(<span class="hljs-string">'100%'</span>).backgroundColor(<span class="hljs-number">0xFFFFFF</span>).height(<span class="hljs-number">100</span>)
}
})
}.divider({ strokeWidth: <span class="hljs-number">2</span>, color: <span class="hljs-string">'#F1F3F5'</span> }).height(<span class="hljs-string">'100%'</span>)
.zIndex(<span class="hljs-number">9</span>)
}
}.width(<span class="hljs-string">"100%"</span>).height(<span class="hljs-string">'100%'</span>)
}
}
更多关于HarmonyOS 鸿蒙Next bindContentCover能设置hitTestBehavior吗的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
HarmonyOS 鸿蒙Next bindContentCover能设置hitTestBehavior。
在HarmonyOS NEXT中,hitTestBehavior是一个重要的属性,它可以设置组件的触摸测试类型,影响组件的触摸测试收集结果,并最终影响后续的触屏事件分发。这一属性在多个场景中都发挥着关键作用,包括处理复杂的多层级组件触摸事件、自定义tabBar的触摸响应等。
虽然官方文档和参考资料中并未直接提及bindContentCover是否能设置hitTestBehavior,但根据HarmonyOS NEXT的组件属性和事件处理机制,可以合理推断,只要bindContentCover是一个可交互的组件或容器,它就应该能够设置hitTestBehavior属性来控制其触摸事件的响应。
因此,开发者可以尝试在bindContentCover组件上设置hitTestBehavior属性,并根据实际需求调整其值(如HitTestMode.Transparent、HitTestMode.Block等)来控制触摸事件的分发和响应。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。