HarmonyOS 无感转场动画推荐方案

HarmonyOS
2024-12-18 15:51:01
766浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

转场动画可参考文档https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-animation-transition-V5

平移滑出可通过设置translate属性实现可以参考这个,向下滑出:

import curves from '@ohos.curves';

@Entry
@Component
struct TransitionEffectDemo {
  @State isPresent: boolean = true;

  // 第一步,创建TransitionEffect
  private effect: TransitionEffect =
    TransitionEffect.OPACITY.animation({ curve: curves.springMotion(0.6, 0.8) })
      .combine(TransitionEffect.translate({ y: 150 }).animation({ curve: curves.springMotion() }))
  build() {
    Stack() {
      if (this.isPresent) {
        Column() {
          Text('ArkUI')
            .fontWeight(FontWeight.Bold)
            .fontSize(20)
            .fontColor(Color.White)
        }
        .justifyContent(FlexAlign.Center)
        .width(150)
        .height(150)
        .borderRadius(10)
        .backgroundColor(0xf56c6c)
        // 第二步:将转场效果通过transition接口设置到组件
        .transition(this.effect)
      }

      // 边框
      Column()
        .width(155)
        .height(155)
        .border({
          width: 5,
          radius: 10,
          color: Color.Black
        })

      // 第三步:新增或者删除组件触发转场,控制新增或者删除组件
      Button('Click')
        .margin({ top: 320 })
        .onClick(() => {
          this.isPresent = !this.isPresent;
        })
    }
    .width('100%')
    .height('60%')
  }
}
  • 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.

可以参考此codelab实例:https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/tutorials_NEXT-TransitionAnimation里面有各种转场动画

ArkTS是不推荐页面转场动画的,为了实现更好的转场效果,推荐使用Navigation组件和模态转场。页面的转场动画请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-page-transition-animation-V5

通过pageTransition函数控制页面的进入和退出,具体进入和退出效果的属性参数以及示例可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-page-transition-animation-V5

分享
微博
QQ
微信
回复
2024-12-18 18:01:56


相关问题
转场动画,谁有好的方案吗?
1158浏览 • 1回复 待解决
HarmonyOS获取设备标识
1031浏览 • 1回复 待解决
HarmonyOS SideBarContainer 转场动画
495浏览 • 1回复 待解决
HarmonyOS 埋点方案
733浏览 • 1回复 待解决
HarmonyOS 创建全局弹窗的推荐方案
605浏览 • 1回复 待解决
HarmonyOS Ability重新启动推荐方案
823浏览 • 1回复 待解决
如何实现动画转场效果
1655浏览 • 1回复 待解决
HarmonyOS Navigation实现Dialog转场动画
654浏览 • 1回复 待解决
瀑布流场景的推荐实现方案
2644浏览 • 1回复 待解决
数据缓存使用方面的推荐方案
1167浏览 • 1回复 待解决
HarmonyOS 页面内的组件转场动画
1015浏览 • 1回复 待解决
HarmonyOS navigation导航转场动画怎么写
690浏览 • 1回复 待解决
HarmonyOS Refresh和页面转场动画demo
594浏览 • 1回复 待解决
Tabs 出现/消失转场动画效果
1009浏览 • 1回复 待解决
如何全局设置页面转场动画
1156浏览 • 1回复 待解决