#鸿蒙通关秘籍#大佬们,ArkUI中组件的显式立即动画怎么用,能指导下吗?

HarmonyOS
23h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
hm673ff052b9053

显式立即动画在ArkUI中,你可以使用animateToImmediately函数来实现,它会立即执行动画,而不需要等待。

@Entry
@Component
struct AnimateToImmediatelyExample {
    @State widthSize: number = 250
    @State heightSize: number = 100
    @State opacitySize: number = 0
    private flag: boolean = true

    build() {
        Column() {
            Column()
                .width(this.widthSize)
                .height(this.heightSize)
                .backgroundColor(Color.Green)
                .opacity(this.opacitySize)
            Button('change size')
                .margin(30)
                .onClick(() => {
                    if (this.flag) {
                        animateToImmediately({
                            delay: 0,
                            duration: 1000
                        }, () => {
                            this.opacitySize = 1
                        })
                        animateTo({
                            delay: 1000,
                            duration: 1000
                        }, () => {
                            this.widthSize = 150
                            this.heightSize = 60
                        })
                    } else {
                        animateToImmediately({
                            delay: 0,
                            duration: 1000
                        }, () => {
                            this.widthSize = 250
                            this.heightSize = 100
                        })
                        animateTo({
                            delay: 1000,
                            duration: 1000
                        }, () => {
                            this.opacitySize = 0
                        })
                    }
                    this.flag = !this.flag
                })
        }.width('100%').margin({ top: 5 })
    }
}
分享
微博
QQ
微信
回复
22h前
相关问题
动画请求绘制帧率
270浏览 • 1回复 待解决
大佬,image decode failed 怎么解决
12207浏览 • 1回复 待解决