请参考示例如下:@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%') } }
请参考示例如下: