通过api写了一个旋转动画的效果,但是这个效果每执行一次都感觉有卡顿问题,不是连续播放的动画效果。
import curves from '@ohos.curves'
@Entry
@Component
struct AnimateToDemo {
@State animate: boolean = false;
// 第一步: 声明相关状态变量
@State rotateValue: number = 0; // 组件一旋转角度
// 第二步:将状态变量设置到相关可动画属性接口
build() {
Stack() {
Column() {
}
.rotate({ angle: this.rotateValue })
.backgroundColor('#317AF7')
.backgroundImage($r('app.media.foreground'))
.justifyContent(FlexAlign.Center)
.width(100)
.height(100)
.borderRadius(30)
.onClick(() => {
animateTo({ curve: curves.springMotion() ,duration:3000,iterations:8,delay:-1}, () => {
this.animate = !this.animate;
// 第三步:闭包内通过状态变量改变UI界面
// 这里可以写任何能改变UI的逻辑比如数组添加,显隐控制,系统会检测改变后的UI界面与之前的UI界面的差异,对有差异的部分添加动画
// 组件一的rotate属性发生变化,所以会给组件一添加rotate旋转动画
this.rotateValue = this.animate ? 360 : 0;
})
})
Text('123')
}
.width('100%')
.height('100%')
}
}
这不是属于卡顿,这个是前后动画的间隔,这边在demo上进行了修改,实现了一直旋转的功能。