HarmonyOS animateTo或animation动画如何取消

看了看文档好像没看到有相关的取消方法

HarmonyOS
2024-12-20 15:41:50
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

如果你需要打断动画可以参考下这个demo,设置一个为0的动画去打断之前的动画。

参考demo:

@Component
@Entry
struct Index {
  @State clickNumber: number = 0;
  @State myScale: number = 1.0;
  uiContext: UIContext | undefined = undefined;
  imageIndex: number = 0
  aboutToAppear() {
    this.uiContext = this.getUIContext?.();
  }
  build() {
    Stack({ alignContent: Alignment.TopEnd }) {
      //木鱼图片
      Image($r('app.media.startIcon'))
        .zIndex(2)
        .width(200)
        .height(200)
        .margin({ top: 300, right: 130 })
        .scale({ x: this.myScale, y: this.myScale })// .clickEffect({level:ClickEffectLevel.LIGHT,scale:0.5})
        .onClick(() => {
          if (!this.uiContext) {
            return;
          }
          //设置一个显示动画为0的动画,去打断之前的动画
          animateTo({ duration: 0, iterations: 1}, () => {
            console.info('this.dur0xxx---', this.myScale)
            this.myScale = 1;
          })
          animateTo({ duration: 1500, iterations: 1 ,onFinish: () => {
            animateTo({ duration: 1500, iterations: 1}, () =>{
              console.info('this.dur2---', this.myScale)
              this.myScale = 1;
            })
          }}, () => {
            console.info('this.dur1---', this.myScale)
            this.myScale = 0.8;
          })
        })
    }.backgroundColor(Color.Black)
    .width('100%')
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:38:51
相关问题
animateTo动画如何直接停止
2849浏览 • 2回复 待解决
HarmonyOSanimateTo如何结束动画
1374浏览 • 2回复 待解决
animateTo动画如何暂停
1232浏览 • 2回复 待解决
HarmonyOS animation动画无法生效
254浏览 • 1回复 待解决
HarmonyOS animation动画停止位置不对
277浏览 • 1回复 待解决
HarmonyOS 动画如何停止或者取消
180浏览 • 1回复 待解决
HarmonyOS animateTo是否能够打断动画
287浏览 • 1回复 待解决
HarmonyOS 如何取消某个组件的动画
214浏览 • 1回复 待解决
HarmonyOS 怎么取消路由跳转动画
257浏览 • 1回复 待解决
HarmonyOS App启动时动画怎么取消
439浏览 • 1回复 待解决
HarmonyOS 怎样实现开屏动画图片?
753浏览 • 1回复 待解决