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 })
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:51:42
相关问题
HarmonyOS动画如何主动停止
430浏览 • 1回复 待解决
HarmonyOS 动画如何停止或者取消?
207浏览 • 1回复 待解决
animateTo动画如何直接停止
2890浏览 • 2回复 待解决
HarmonyOS 如何停止无限旋转中动画
295浏览 • 1回复 待解决
HarmonyOS 属性动画中途如何停止
724浏览 • 1回复 待解决
服务卡片进度条如何停止动画
9348浏览 • 1回复 待解决
HarmonyOS animation动画停止位置不对
304浏览 • 1回复 待解决
如何停止UIAbility自身
2159浏览 • 1回复 待解决