#鸿蒙通关秘籍#如何为鸿蒙应用设置连续按下按钮的动画衔接?

HarmonyOS
2024-12-05 14:49:11
848浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
暖阳初照YAML

要实现按钮连续按下动画的平滑衔接,只需在状态改变时更新动画的终点值,系统会确保动画的平滑过渡:

import { curves } from '@kit.ArkUI';
class SetSlt {
  isAnimation: boolean = true
  set(): void {
    this.isAnimation = !this.isAnimation;
  }
}

@Entry
@Component
struct AnimationToAnimationDemo {
  @State SetAnimation: SetSlt = new SetSlt();

  build() {
    Column() {
      Text('ArkUI')
        .fontWeight(FontWeight.Bold)
        .fontSize(12)
        .fontColor(Color.White)
        .textAlign(TextAlign.Center)
        .borderRadius(10)
        .backgroundColor(0xf56c6c)
        .width(100)
        .height(100)
        .scale({ x: this.SetAnimation.isAnimation ? 2 : 1, y: this.SetAnimation.isAnimation ? 2 : 1 })
        .animation({ curve: curves.springMotion(0.4, 0.8) })

      Button('Click')
        .margin({ top: 200 })
        .onClick(() => {
          this.SetAnimation.set()
        })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 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.

通过这样的设计,可以实现多个连续点击后的动画流畅过渡,实现最佳的用户体验。

分享
微博
QQ
微信
回复
2024-12-05 16:15:32


相关问题
鸿蒙jsUi如何制作按钮动效
9526浏览 • 3回复 待解决