HarmonyOS animateTo是否能够打断动画

HarmonyOS
2024-12-24 18:22:44
1.2w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请参考示例如下:

@Entry
@Component
struct Index {
  @State angle: number = 0;
  isPlaying: boolean = false;

  build() {
    Column() {
      Text("abc")
        .borderWidth(1)
        .rotate({angle:this.angle})

      Row() {
        Text("start")
          .onClick(() => {
            if (this.isPlaying) {
              return;
            }
            this.angle = 0;
            animateTo({iterations: -1, curve:Curve.Linear}, ()=> {
              this.angle = 360;
            });
            this.isPlaying = true;
          })
        Text("stop")
          .onClick(() => {
            if (this.isPlaying) {
              animateTo({ duration: 0 }, () => {
                // 在duration为0的动画里改变要停下来的属性值
                this.angle = 0;
              })
              this.isPlaying = false;
            }
          })
      }.width("100%").justifyContent(FlexAlign.SpaceAround).margin({ top: 50 })
    }.width('100%')
  }
}
  • 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-24 20:11:17


相关问题
框架是否能够拉起应用APP
3711浏览 • 2回复 待解决
是否能够自定义router跳转的url
1254浏览 • 1回复 待解决
IPC跨进程通讯是否能够异步返回数据
787浏览 • 1回复 待解决
在元服务中是否能够获取到OAID?
484浏览 • 0回复 待解决
animateTo动画如何暂停
1314浏览 • 2回复 待解决
HarmonyOSanimateTo如何结束动画
1502浏览 • 2回复 待解决
animateTo动画如何直接停止
2982浏览 • 2回复 待解决
refresh期望能够自定义loading动画
1221浏览 • 1回复 待解决