中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如果通过双指缩放对grid进行放大缩小?
微信扫码分享
@Entry @Component struct Index { @State list: string[] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] @State columnsTemp :string= "1fr 1fr" @State h:number = 150 build() { Column() { Grid() { ForEach(this.list, (e: string) => { GridItem() { Text(e) .width("100%") .height(this.h) .textAlign(TextAlign.Center) .fontColor(Color.White) .backgroundColor(Color.Red) } }) } .columnsTemplate(this.columnsTemp) .columnsGap(5) .rowsGap(5) } .height('100%') .width('100%') .gesture(PinchGesture({ fingers: 2 }).onActionUpdate(e => { if (e.scale>1) { this.columnsTemp = "1fr 1fr" this.h = 150 }else{ this.columnsTemp = "1fr 1fr 1fr" this.h = 100 } })) } }