#鸿蒙通关秘籍#如何使用ArkUI中的传统曲线实现旋转动画效果

HarmonyOS
2024-12-06 14:19:01
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
幽兰空谷ASIC

在ArkUI中,可以使用传统曲线实现动画应用中常见的旋转效果。以下是实现旋转动画效果的代码示例,通过点击触发旋转效果,动画重复执行。

@Entry
@Component
export struct CurveDemo {
  @State dRotate: number = 0; // 旋转角度
  
  build() {
    Column() {
      // 摆动管道
      Stack() {
        Row()
          .width(290)
          .height(290)
          .border({
            width: 15,
            color: 0xE6E8EB,
            radius: 145
          })

        ForEach(myCurves, (item: MyCurve) => {
          // 小球
          Column() {
            Row()
              .width(30)
              .height(30)
              .borderRadius(15)
              .backgroundColor(item.color)
          }
          .width(20)
          .height(300)
          .rotate({ angle: this.dRotate })
          .animation({ duration: 2000, iterations: -1, curve: item.curve, delay: 100 })
        })
      }
      .width('100%')
      .height(200)
      .onClick(() => {
        this.dRotate ? null : this.dRotate = 360;
      })
    }
    .width('100%')
  }
}
  • 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.

通过使用rotate()animation()方法来定义旋转动画效果,结合传统曲线实现自然流畅的旋转效果。

分享
微博
QQ
微信
回复
2024-12-06 15:07:43


相关问题
HarmonyOS 旋转动画效果
529浏览 • 1回复 待解决
HarmonyOS 如何实现旋转动画
943浏览 • 1回复 待解决
如何使用弹簧动画曲线
1562浏览 • 1回复 待解决