HarmonyOS position设置x,y值的更改,没有平移动画

HarmonyOS
2024-12-24 16:47:10
1055浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

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 })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
分享
微博
QQ
微信
回复
2024-12-24 19:55:11


相关问题
HarmonyOS 平移动画
711浏览 • 1回复 待解决
HarmonyOS 平移动画问题
523浏览 • 1回复 待解决
HarmonyOS如何获取inputTextXY
942浏览 • 1回复 待解决
Tabs组件选中下划线需要平移动
2285浏览 • 1回复 待解决
HarmonyOS list设置问题
431浏览 • 1回复 待解决
HarmonyOS 没有全局api loading动画
1249浏览 • 1回复 待解决