【HarmonyOS NEXT】在swipe嵌套web/list存在垂直滚动时,在用户垂直滚动,能否禁用swipe的左右滑动

 【关键字】

swipe/ 嵌套 / web / list / 滚动 / 禁用滑动

【问题描述】

在swipe嵌套web/list存在垂直滚动时,在用户垂直滚动,能否禁用swipe的左右滑动?

【解决方案】

可以使用disableSwipe方法禁用组件滑动切换功能。

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-container-swiper-0000001862607461#ZH-CN_TOPIC_0000001862607461__%E5%B1%9E%E6%80%A7

简单示例如下:

import web_webview from '@ohos.web.webview'

@Entry
@Component
struct SwiperPage {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
private swiperController: SwiperController = new SwiperController()
controller: web_webview.WebviewController = new web_webview.WebviewController()
@State canSwipe: boolean = false

build() {
Column() {
Swiper(this.swiperController) {
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item: number) => {
ListItem() {
Text('' + item)
.width('100%')
.height(100)
.fontSize(16)
.textAlign(TextAlign.Center)
}
}, (item: string) => item)
}.width('90%')
.height('90%')

Text('1')
.width('90%')
.height('90%')
.textAlign(TextAlign.Center)
.fontSize(30)

Web({ src: 'https://www.taobao.com/', controller: this.controller })
.width('90%')
.height('90%')
.onTouch((event?: TouchEvent) => { // 具体处理逻辑根据实际需求修改,这里仅作为示例参考
if (event) {
if (event.type === TouchType.Down || event.type === TouchType.Move) {
this.canSwipe = true
} else {
this.canSwipe = false
}
}
})
}
.interval(3000)
.autoPlay(true)
.disableSwipe(this.canSwipe)
}
.width('100%')
.height('100%')
}
}

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值