完整示例参考如下:
@Entry @Component struct TranslateIndex { @State flag: boolean = false; build() { Column() { Image($r('app.media.startIcon')) // 根据场景需要添加图片 .width('50%') .height('50%') .objectFit(ImageFit.Auto) .onClick(() => { this.getUIContext()?.animateTo({ duration: 1000, curve: Curve.EaseOut, playMode: PlayMode.Normal, }, () => { this.flag = true; }); }); } .width('80%') .translate({ y: this.flag ? 400 : 0 }) .height('100%') .width('100%'); } }