#鸿蒙通关秘籍#如何实现地址交换动画效果?

HarmonyOS
2024-12-03 12:26:25
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
云海谜OLTP

要实现地址交换动画效果,可以参考以下步骤:

  1. 使用两个 Text 组件来展示左右两边的地址。首先设置 Text 组件的初始偏移量以及文本对齐方式。可以使用以下代码:

    Row() {
      Text($r('app.string.address_exchange_address_left'))
        .translate({ x: this.translateX })
        .width($r('app.string.address_exchange_address_width'))
        .textAlign(this.swap ? TextAlign.End : TextAlign.Start)
      ...
      Text($r('app.string.address_exchange_address_right'))
        .translate({ x: -this.translateX })
        .width($r('app.string.address_exchange_address_width'))
        .textAlign(this.swap ? TextAlign.Start : TextAlign.End)
      ...
    }
    
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
    • 11.
    • 12.
  2. 点击中间的图标时,调整偏移量来切换左右地址。通过 animateTo 函数来更新偏移量并完成动画效果:

    Stack() {
      Image($r('app.media.address_exchange_airplane'))
        .size({
            height: $r('app.integer.address_exchange_airplane_size'),
            width: $r('app.integer.address_exchange_airplane_size')
        })
      Image($r('app.media.address_exchange_recycle'))
        .size({
            height: $r('app.integer.address_exchange_recycle_size'),
            width: $r('app.integer.address_exchange_recycle_size')
        })
        .rotate({ angle: this.rotateAngle })
        .animation({
            curve: Curve.EaseOut,
            playMode: PlayMode.Normal,
        })
    }
      .width($r('app.string.address_exchange_image_width'))
      .onClick(() => {
        this.swap = !this.swap
        animateTo({ curve: curves.springMotion() }, () => {
            if (this.swap) {
                this.translateX = this.distance;
            } else {
                this.translateX = this.zeroTranslate;
            }
        })
        this.rotateAngle += this.rotateAddAngle;
      })
    
    • 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.
分享
微博
QQ
微信
回复
2024-12-03 14:28:55


相关问题