#鸿蒙学习大百科#如何实现共享元素转场?

如何实现共享元素转场?

HarmonyOS
2024-10-25 11:02:49
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
朝花惜拾丶

添加geometryTransition属性,id参数必须在两个NavDestination之间保持一致。

@Component
export struct A {
  @Consume pageStack: NavPathStack
  build() {
    NavDestination() {
      Column() {
        Text("A")
        Button("jump to B")
          .geometryTransition('sharedId')
          .onClick(()=>{
            this.getUIContext()?.animateTo({ duration: 1000 }, () => {
              this.pageStack.pushPath({ name: 'B' }, false)
            })
          })
      }.width("100%")
      .height("100%")
      .justifyContent(FlexAlign.Center)
    }
    .hideTitleBar(true)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
@Component
export struct B {
  @Consume pageStack: NavPathStack
  build() {
    NavDestination() {
      Column() {
        Text("B")
        Button("jump to A")
          .geometryTransition('sharedId')
          .onClick(()=>{
          })
      }.width("100%")
      .height("100%")
      .justifyContent(FlexAlign.Center)
    }
    .hideTitleBar(true)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
分享
微博
QQ
微信
回复
2024-10-25 15:48:09
相关问题
如何实现共享元素转场
825浏览 • 1回复 待解决
#鸿蒙学习大百科#如何实现ui优化?
764浏览 • 1回复 待解决