Swiper 结合 Image使用,Image组件通过scale属性缩放后, 超出swiper单页的区域应该不显示, 现在显示效果异常,有没有好的解决方案
目前我Image组件监听Pan手势控制translate属性实现图片拖动,我想要放大的Image拖到边缘自动触发Swiper的next事件,应该如何处理
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
private sc = new SwiperController()
@State private scaleValue: number = 1
build() {
Stack(){
Swiper(this.sc) {
Column() {
Image("https://img.***.com/imgextra/i3/1917047079/O1CN01JX9jtW22AEclEOGq3_!!2-item_pic.png")
.objectFit(ImageFit.Auto)
.width(`${720 * this.scaleValue}lpx`)
.scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
.gesture(
// 监听捏合手势事件
PinchGesture({ fingers: 2 })
.onActionStart(() => {
console.log('pinch start');
})
.onActionUpdate((event: GestureEvent | undefined) => {
if (event) {
this.scaleValue = event.scale;
}
})
.onActionEnd(() => {
this.scaleValue = 1
})
)
}.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
Column() {
Image("https://img.***.com/imgextra/i2/O1CN01lX3caY1cDjfPguEwb_!!0-tbbala.jpg")
.objectFit(ImageFit.Auto)
.width(`${720 * this.scaleValue}lpx`)
.scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
.gesture(
// 监听捏合手势事件
PinchGesture({ fingers: 2 })
.onActionStart(() => {
console.log('pinch start');
})
.onActionUpdate((event: GestureEvent | undefined) => {
if (event) {
this.scaleValue = event.scale;
console.log("" + event.scale)
} else {
hilog.error(0x3d00, 'JSAPP', 'undefined event')
}
})
.onActionEnd(() => {
this.scaleValue = 1
})
)
}.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}.indicator(false)
.autoPlay(false)
.loop(false)
Row() {
Text('x')
.fontFamily('tbIconFont')
.fontSize(16)
.fontColor(Color.White)
Text('0/0')
.fontFamily('tbIconFont')
.fontSize(16)
.fontColor(Color.White)
Text('x')
.fontFamily('tbIconFont')
.fontSize(16)
.fontColor(Color.White)
}.padding({
left:'12lpx',
right:'12lpx',
top:'12lpx'
})
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
}.width('100%').height('100%').backgroundColor('#9a000000')
.alignContent(Alignment.TopStart)
}
}
请参考以下代码调用 CommonImagePage, 传入 imageModel, imageModel 的 imageArray里为图片列表,currentIndex为当前点击图片的索引。