HarmonyOS 自定义弹窗 @CustomDialog 如何设置从底部升起的动画?

HarmonyOS  自定义弹窗 @CustomDialog 如何设置从底部升起的动画?

HarmonyOS
2024-09-25 12:36:18
1161浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu
@CustomDialog  
struct CustomDialogExample {  
  controller: CustomDialogController  
  @State showFlag: Visibility = Visibility.Visible;  
  
  build() {  
    Column() {  
      Button("关闭弹窗")  
    }  
    .width("100%")  
    .height(400)  
    .backgroundColor(Color.Gray)  
    .onClick(() => {  
      this.cancel();  
    })  
    .visibility(this.showFlag) //核心代码 设置动画事件为200ms ,设置组件转场时插入的起点和删除的终点为屏幕以下100vp  
    .transition(TransitionEffect.OPACITY.animation({ duration: 200 }).combine(TransitionEffect.translate({ y: 100 })))  
  } //在删除的时候需要注意,如果弹窗直接关闭是没有转场效果的,可以先用显隐控制, //设置弹窗为隐藏,此时弹出向下退出的动效生效,再设置延时关闭弹窗。  
  
  cancel() {  
    this.showFlag = Visibility.Hidden  
    setTimeout(() => {  
      this.controller.close()  
    }, 200)  
  }  
}  
  
@Entry  
@Component  
struct CustomDialogUser {  
  dialogController: CustomDialogController =  
    new CustomDialogController({ builder: CustomDialogExample(), autoCancel: false, customStyle: true })  
  
  build() {  
    Column() {  
      Button('click me').onClick(() => {  
        this.dialogController.open()  
      })  
    }.width('100%').height('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.
分享
微博
QQ
微信
回复
2024-09-25 16:24:13
相关问题
CustomDialog自定义动画
1369浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
795浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1380浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
819浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
1320浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1988浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog调用问题
1162浏览 • 1回复 待解决
CustomDialog不支持自定义动画
1204浏览 • 2回复 待解决
HarmonyOS 如何设置自定义弹窗透明
941浏览 • 1回复 待解决
如何设置自定义弹窗位置
2845浏览 • 1回复 待解决