HarmonyOS/OpenHarmony应用开发-显示动画

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

提供全局animateTo显式动画接口来指定由于闭包代码导致的状态变化插入过渡动效。
说明:从API Version 7开始支持。开发语言ets.

接口:animateTo(value: AnimateParam, event: ()=> void) : void
描述:提供全局animateTo显式动画接口来指定由于闭包代码导致的状态变化插入过渡动效。
event指定显示动效的闭包函数,在闭包函数中导致的状态变化系统会自动插入过渡动画。
HarmonyOS/OpenHarmony应用开发-显示动画-鸿蒙开发者社区
示例代码:

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

  build() {
    Column() {
      Button('change width and height')
        .width(this.widthSize)
        .height(this.heightSize)
        .margin(30)
        .onClick(() => {
          if (this.flag) {
            animateTo({
              duration: 2000, // 动画时长
              curve: Curve.EaseOut, // 动画曲线
              iterations: 2, // 播放次数
              playMode: PlayMode.Normal,// 动画模式
              onFinish: () => {
                console.info('play end')
              }
            }, () => {
              this.widthSize = 100;
              this.heightSize = 50;
            })
          } else {
            animateTo({}, () => {
              this.widthSize = 250
              this.heightSize = 100
            })
          }
          this.flag = !this.flag
        })

      Row(){
        Text('change rotate angle').fontSize(20)
      }
      .width(250)
      .height(50)
      .backgroundColor(0xf45645)
      .justifyContent(FlexAlign.Center)
      .rotate({ angle: this.rotateAngle})
      .onClick(() => {
        if(this.flag){
          animateTo({
            duration: 1200,
            curve: Curve.Friction,
            delay: 500,
            iterations: 1, // 设置-1表示动画无限循环
            playMode: PlayMode.AlternateReverse,
            onFinish: () => {
              console.info('play end1')
            }
          }, () => {
            this.rotateAngle = 90;
          })
        }
      })
    }.width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
    .alignItems(HorizontalAlign.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.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.

示例效果:
HarmonyOS/OpenHarmony应用开发-显示动画-鸿蒙开发者社区
这里还要说的是的,这里的rotate好像不生效,不知道是不是版本原因,后续会查找原因.
HarmonyOS/OpenHarmony应用开发-显示动画-鸿蒙开发者社区

代码地址:https://gitee.com/jltfcloudcn/jump_to/tree/master/AnimationMuster

标签
HarmonyOSOpenHarmony应用开发-显示动画.docx 91.28K 26次下载
收藏
回复
举报


回复
    相关推荐