HarmonyOS/OpenHarmony应用开发-路径动画

鸿蒙时代
发布于 2022-12-30 14:45
浏览
0收藏

设置组件进行位移动画时的运动路径。

说明:从API Version 7开始支持。开发语言ets.
HarmonyOS/OpenHarmony应用开发-路径动画-鸿蒙开发者社区
示例代码:

@Entry
@Component
struct PathAnimation {
  @State toggle: boolean = true

  build() {
    Column() {
      Button('click me')
        // 执行动画:从起点移动到(300,200),再到(300,500),再到终点
        .motionPath({ path:  'Mstart.x start.y L400 300 L300 500 Lend.x end.y', from: 0.0, to: 1.0, rotatable: true })
        .onClick(() => {
          animateTo({ duration: 4000, curve: Curve.Linear }, () => {
            this.toggle = !this.toggle // 通过this.toggle变化组件的位置
          })
        })
    }.width('100%').height('50%').borderWidth(2)
    .alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.End)
    .justifyContent(this.toggle ? FlexAlign.Start : FlexAlign.End)
  }
}

示例效果:

HarmonyOS/OpenHarmony应用开发-路径动画-鸿蒙开发者社区

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

标签
HarmonyOSOpenHarmony应用开发-路径动画.docx 37.31K 5次下载
收藏
回复
举报
回复
    相关推荐