鸿蒙5.0开发常见问题【如何实现类似keyframes的效果?】
·
可以通过delay动画或在onFinish回调中启动新动画来实现类似效果。参考代码如下:
@Entry
@Component
struct AnimateToExample {
@State widthSize: number = 250;
@State heightSize: number = 100;
@State rotateAngle: number = 0;
private flag: boolean = true;
@State opacityValue: number = 1;
build() {
Column() {
Button('change size')
.width(this.widthSize)
.height(this.heightSize)
.margin(30)
.opacity(this.opacityValue)
.onClick(() => {
if (this.flag) {
this.getUIContext().animateTo({
duration: 2000,
curve: Curve.EaseOut,
iterations: 1,
playMode: PlayMode.Normal,
onFinish: () => {
this.getUIContext().animateTo({
duration: 2000,
curve: Curve.EaseOut,
iterations: 1,
playMode: PlayMode.Normal,
onFinish: () => {
}
}, () => {
this.opacityValue = 0.2;
})
}
}, () => {
this.opacityValue = 0.5;
})
}
})
}.width('100%').margin({ top: 5 })
}
}
更多推荐



所有评论(0)