HarmonyOS 如何停止动画,回到初始的静止状态

如何停止动画,回到初始的静止状态

HarmonyOS
2024-12-20 17:11:00
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考demo:

// xxx.ets
@Entry
@Component
struct AnimateToExample {
  @State widthSize: number = 250
  @State heightSize: number = 100
  @State rotateAngle: number = 0
  private flag: boolean = true
  build() {
    Column() {
      Button('change size')
        .width(this.widthSize)
        .height(this.heightSize)
        .margin(30)
        .onClick(() => {
          if (this.flag) {
            animateTo({
              duration: 2000,
              curve: Curve.EaseOut,
              iterations: 3,
              playMode: PlayMode.Normal,
              onFinish: () => {
                console.info('play end')
              }
            }, () => {
              this.widthSize = 150
              this.heightSize = 60
            })
          } else {
            animateTo({
              duration: 0,
            }, () => {
              this.widthSize = 250
              this.heightSize = 100
            })
          }
          this.flag = !this.flag
          if (!this.flag) {
            animateTo({
              duration: 2000,
              curve: Curve.EaseOut,
              iterations: 3,
              playMode: PlayMode.Normal,
              onFinish: () => {
                console.info('play end')
              }
            }, () => {
              this.widthSize = 150
              this.heightSize = 60
            })
          }
        })
    }.width('100%').margin({ top: 5 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-20 18:51:42


相关问题
HarmonyOS动画如何主动停止
533浏览 • 1回复 待解决
animateTo动画如何直接停止
3008浏览 • 2回复 待解决
HarmonyOS 动画如何停止或者取消?
380浏览 • 1回复 待解决
HarmonyOS 如何停止无限旋转中动画
511浏览 • 1回复 待解决
HarmonyOS 属性动画中途如何停止
795浏览 • 1回复 待解决
HarmonyOS animation动画停止位置不对
388浏览 • 1回复 待解决
服务卡片进度条如何停止动画
9402浏览 • 1回复 待解决
如何停止UIAbility自身
2238浏览 • 1回复 待解决