中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
@Entry @Component struct Scroll_Free { private scrollController: Scroller = new Scroller(); private scrollControllerOut: Scroller = new Scroller(); @State scaleValue: number = 1; @State pinchValue: number = 1; @State pinchX: number = 0; @State pinchY: number = 0; aboutToAppear(): void { let list: number[] = [] for (let i = 1; i <= 10; i++) { list.push(i); } } build() { Column() { Scroll(this.scrollControllerOut) { Scroll(this.scrollController) { Column() { Image($r('app.media.mid')) .height(1000) .width(600) } } .scrollable(ScrollDirection.Horizontal) .nestedScroll({ scrollForward: NestedScrollMode.PARALLEL, scrollBackward: NestedScrollMode.PARALLEL }) } .scrollable(ScrollDirection.Vertical) .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 }) .gesture(PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent | undefined) => { console.info('Pinch start'); }) // 当捏合手势触发时,可以通过回调函数获取缩放比例,从而修改组件的缩放比例 .onActionUpdate((event: GestureEvent | undefined) => { if (event) { this.scaleValue = this.pinchValue * event.scale; this.pinchX = event.pinchCenterX; this.pinchY = event.pinchCenterY; } }) .onActionEnd(() => { this.pinchValue = this.scaleValue; console.info('Pinch end'); }) ) }.height('100%').width('100%') } }