HarmonyOS 属性动画播放次数设置为无限次播放时,怎样手动结束动画?

import { curves } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State widthValue: number = 38;
  @State scaleValue: number = 1;
  @State iterations: number = -1;

  build() {
    Column(){
      Text('开始')
        .fontSize(16)
        .width(40).height(20)
        .onClick(()=>{
          animateTo({
            duration: 450,
            curve: Curve.EaseInOut,
            iterations: this.iterations,
            playMode:PlayMode.Alternate,
            onFinish: () => {
              console.log('--哈哈哈---')
            }
          }, () => {
            this.scaleValue =  1.2
          })
        })
      Text('结束')
        .fontSize(16)
        .width(40).height(20)
        .margin({top:20})
        .onClick(()=>{
          this.iterations = 1
        })
      Stack({alignContent:Alignment.Center}){
        Row()
          .width(32)
          .height(32)
          .backgroundColor(Color.Orange)
          .borderRadius(16)
          .scale({x:this.scaleValue,y:this.scaleValue})

        Row(){

        }
        .width(this.widthValue)
        .height(this.widthValue)
        .backgroundColor(Color.Transparent)
        .borderRadius(1080)
        .borderWidth(2)
        .borderColor(Color.Red)
        .scale({x:this.scaleValue,y:this.scaleValue})
      }.margin({top:50})
    }.margin({left:200,top:150})

  }
}

iterations设置为-1后,应该怎么手动结束动画

阅读 573
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进