在需要屏蔽Swiper组件切换效果的组件上使用PanGesture消费掉左右滚动事件。
@Entry @Component struct TestSwiperPage { private swiperController: SwiperController = new SwiperController(); private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left | PanDirection.Right }); build() { Column() { Swiper(this.swiperController) { Text('前') .width('90%') .height('90%') .textAlign(TextAlign.Center) .fontSize(15); Scroll() { Column() { Column() { Text('此区域不可正常操作').fontColor(Color.Black).fontSize(15); } .alignItems(HorizontalAlign.Center) .justifyContent(FlexAlign.Center) .height(200) .width('100%') .backgroundColor('#ffcdc9c9') .gesture( PanGesture(this.panOption) ); Column() { Text('此区域可正常操作').fontColor(Color.Black).fontSize(15).margin({ top: 200 }); }.height(2000) .width('100%') .backgroundColor('#ff97b6f3'); }; } .width('90%') .height('100%'); Text('后') .width('90%') .height('90%') .textAlign(TextAlign.Center) .fontSize(15); } .interval(3000) .autoPlay(false) .height('100%'); } .width('100%') .height('100%') .backgroundColor(Color.White); } }