HarmonyOS/OpenHarmony应用开发-属性动画

鸿蒙时代
发布于 2023-1-3 10:38
浏览
0收藏

组件的某些通用属性变化时,可以通过属性动画实现渐变过渡效果,提升用户体验。支持的属性包括width、height、backgroundColor、opacity、scale、rotate、translate等。
说明:从API Version 7开始支持。开发语言ets.
HarmonyOS/OpenHarmony应用开发-属性动画-鸿蒙开发者社区
HarmonyOS/OpenHarmony应用开发-属性动画-鸿蒙开发者社区
示例代码:

@Entry
@Component
struct AttrAnimation {
  @State widthSize: number = 200;
  @State heightSize: number = 100;
  @State fontSize: number = 20;
  @State attrFlag: boolean = true;

  build() {
    Column() {
      Row(){
        Text(this.attrFlag ? '点击缩小':'点击变大').fontSize(this.fontSize)
      }.onClick(() => {
        if (this.attrFlag) {
          this.widthSize = 100
          this.heightSize = 50
        } else {
          this.widthSize = 200
          this.heightSize = 100
        }
        this.attrFlag = !this.attrFlag
      }).width(this.widthSize)
      .height(this.heightSize)
      .backgroundColor(0x317aff)
      .justifyContent(FlexAlign.Center)
      .animation({
        duration: 2000, // 动画时长
        tempo:2,//动画播放速度
        curve: Curve.EaseOut, // 动画曲线
        delay: 500, // 动画延迟
        iterations: 1, // 播放次数
        playMode: PlayMode.Normal // 动画模式
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}

  • 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.
  • 38.
  • 39.
  • 40.

示例效果:
HarmonyOS/OpenHarmony应用开发-属性动画-鸿蒙开发者社区

标签
收藏
回复
举报
回复
    相关推荐