position的x,y值更改,只存在过渡动画的,只是变化太快,肉眼无法分辨。代码参考:const HEIGHT_TITLE = 44; @Entry @Component struct TestTranslatePage { @Prop isTranslateSearch: boolean = false; build() { Row() { Stack() { Image($r('app.media.startIcon')) .width(HEIGHT_TITLE - 12) .height(HEIGHT_TITLE - 12) .margin({ left: $r('app.float.tab_margin_top') }) Image($r('app.media.scan')) .width(HEIGHT_TITLE - 12) .height(HEIGHT_TITLE - 12) .margin({ left: $r('app.float.tab_margin_top') }) .translate(this.isTranslateSearch ? { x: 50, y: 0 } : { x: 0, y: 0 }) .animation({ duration: this.isTranslateSearch ? 600 : 300, playMode: PlayMode.Normal }) Image($r('app.media.male')) .width(HEIGHT_TITLE - 12) .height(HEIGHT_TITLE - 12) .margin({ left: $r('app.float.tab_margin_top') }) .translate(this.isTranslateSearch ? { x: 100, y: 0 } : { x: 0, y: 0 }) .animation({ duration: this.isTranslateSearch ? 300 : 600, playMode: PlayMode.Normal }) } Row() { Image($r('app.media.app_icon')) .width(HEIGHT_TITLE / 2) .height(HEIGHT_TITLE / 2) .position(this.isTranslateSearch ? { x: '55%', y: '25%' } : { y: '25%' }) .animation({ duration: 600 }) .onClick(() => { this.isTranslateSearch = !this.isTranslateSearch }) TextInput({ placeholder: '请输入搜索内容' }) .height(HEIGHT_TITLE - 2) .width(this.isTranslateSearch ? '10%' : '50%') .backgroundColor("#eeeeee") .scale(this.isTranslateSearch ? { x: 0.0, y: 1 } : { x: 1, y: 1 }) .translate(this.isTranslateSearch ? { x: 150, y: 0 } : { x: 0, y: 0 }) .animation({ duration: 500, playMode: PlayMode.Normal }) .margin({ left: $r('app.float.navigation_margin_left') }) .focusable(false) } .alignItems(VerticalAlign.Center) .margin({ left: $r('app.float.height_title') }) Row() { Image($r('app.media.img')) .width(HEIGHT_TITLE / 2) .height(HEIGHT_TITLE / 2) .position(this.isTranslateSearch ? { x: '82%', y: '15%' } : { x: '60%', y: '15' }) .animation({ duration:500 }) } .alignItems(VerticalAlign.Center) .position({ x: '82%', y: '15%' }) } .width('100%') .height(HEIGHT_TITLE) .backgroundColor(Color.White) .position({ x: 0, y: 0 }) .margin({ top: 300 }) } }
position的x,y值更改,只存在过渡动画的,只是变化太快,肉眼无法分辨。代码参考: