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

如何实现共享元素转场?

HarmonyOS
2天前
浏览
收藏 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)
  }
}
@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)
  }
}
分享
微博
QQ
微信
回复
2天前
提问
该提问已有0人参与 ,帮助了0人