HarmonyOS animateTo是否能够打断动画?

如题:HarmonyOS animateTo是否能够打断动画?

阅读 556
1 个回答

请参考示例如下:

@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%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进