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})

  }
}
  • 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.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.

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

HarmonyOS
2024-12-24 16:41:10
386浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

可以通过新启一个duration为0的animateTo来结束动画

参考链接:https://gitee.com/XiaoBaiAHui/arkui_animation_fag

分享
微博
QQ
微信
回复
2024-12-24 18:08:42
相关问题
动画lottie能否设置播放次数
2698浏览 • 1回复 待解决
HarmonyOS 如何播放pag动画
650浏览 • 1回复 待解决
HarmonyOS 本地lottie动画无法播放
1426浏览 • 1回复 待解决
TransitionEffect动画循环播放如何关闭
2394浏览 • 1回复 待解决
HarmonyOS 如何监控动画结束
808浏览 • 1回复 待解决
HarmonyOS中animateTo如何结束动画
1859浏览 • 2回复 待解决
HarmonyOS 如何停止无限旋转中的动画
915浏览 • 1回复 待解决
HarmonyOS 怎样加载Lottie动画
786浏览 • 1回复 待解决