HarmonyOS transition如果设置move或者traslate动画,加上animation.duration 会导致组件先消失

代码如下:

@Preview  
@Component  
export default struct Test {  
  onDestinationBack: () => boolean = () => false;  
  @State toolsShow: boolean = false  
  aboutToAppear() {  
  
  }  
  
  build() {  
    NavDestination() {  
      Stack({ alignContent: Alignment.Top }) {  
  
        Row() {  
          Text('我是下滑组件').fontColor(Color.Red)  
        }  
        .width('100%')  
        .height(100)  
        .backgroundColor(0xBF000000)  
        .justifyContent(FlexAlign.Center)  
        .visibility(this.toolsShow ? Visibility.Visible : Visibility.None)  
        .transition(TransitionEffect.move(TransitionEdge.TOP).animation({ duration: 1000 }))  
  
        //.transition(TransitionEffect.move(TransitionEdge.TOP))  
        //.transition(TransitionEffect.translate({ y: -300 }).animation({ duration: 500 }))  
        Row() {  
          Text('点我顶部滑出').onClick(() => {  
            this.toolsShow = !this.toolsShow  
          })  
        }  
        .width(120)  
        .height(30)  
        .backgroundColor(Color.Green)  
        .margin({ top: 280 })  
        .justifyContent(FlexAlign.Center)  
  
  
        //.alignItems(this.alignSelf.Start)  
      }.border({ width: 1 })  
      .width('100%')  
  
      Text('任意点击收缩')  
  
    }  
    .backgroundColor(Color.Gray)  
    .hideTitleBar(true)  
    .onTouch((event?: TouchEvent) => {  
      if (event?.type == TouchType.Up) {  
        this.toolsShow = false  
      }  
  
    })  
  }  
}
  • 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.
  • 51.
  • 52.
  • 53.
  • 54.
HarmonyOS
2024-09-25 13:02:25
74浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

在有动画参与的情况下,动画需要去参与布局和占位,尝试使用if/else控制组件显隐。

分享
微博
QQ
微信
回复
2024-09-25 16:18:49


相关问题
HarmonyOS animation动画无法生效
525浏览 • 1回复 待解决
HarmonyOS animation动画停止位置不对
493浏览 • 1回复 待解决
Tabs 出现/消失转场动画效果
944浏览 • 1回复 待解决
HarmonyOS 自动签名导致appid变化
617浏览 • 1回复 待解决