#鸿蒙通关秘籍#请教一下,ArkUI中组件的属性动画怎么玩,有人能帮帮吗?

HarmonyOS
2024-11-27 15:15:19
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
CodeCobra
属性动画啊,属性动画在ArkUI中,你可以使用`animateTo`函数来实现,通过它你可以对组件进行精确的动画控制。

@Component
struct MyAnimatedComponent {
@State isBlue: boolean = false
build() {
Text('Hello World')
.fontColor(this.isBlue ? `Color.Blue` : `Color.Black`)

Button(this.isBlue ? 'click to black' : 'click to blue')
.onClick(()=>{
animateTo({
duration: 500
}, () => {
this.isBlue = !this.isBlue;
})
})
}
}

import { animated, Vector4 } from '@ohos/arkui';

@Entry@Component
struct MyAnimatedComponent {
@animated position = new Vector4(0, 0, 0, 0);

build() {
Column() {
View()
.width(100)
.height(100)
.backgroundColor(`0xffff0000`)
.position(this.position)
.animateTo({ x: 100, y: 100 }, { duration: 1000 });
}
}
}
  • 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.
分享
微博
QQ
微信
回复
2024-11-27 16:25:23
相关问题