文档管理中心
我的
|

HarmonyOS 5

二级浮层的出场动画实现

问题描述:

二级浮层的出场动画实现。

点赞
收藏
回复
1
分享
举报
浏览156 发布于2024-06-17 10:31未知归属地
全部评论
最多点赞
最新发布
最早发布

解决方案:

以下示例代码可以实现进场由下到上,出场由上到下

收起
自动换行
深色代码主题
复制
let anmDuration: number = 500; 
 
// 弹窗交互 
@CustomDialog 
struct CustomDialogExample { 
  @State showFlag: Visibility = Visibility.Visible; 
  @State isAutoCancel: boolean = false; 
  controller: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample({}), 
    autoCancel: true, 
  }) 
 
  build() { 
    Column() { 
      Text('我是内容') 
        .fontSize(20) 
        .margin({ top: 10, bottom: 10 }) 
        .backgroundColor('#FFFFFF') 
        .textAlign(TextAlign.Center) 
        .height(400) 
        .width('100%') 
        .margin({ top: 400 }) 
        .onClick(() => { 
          this.cancel(); 
        }) 
    } 
    .width('100%') 
    .height('100%') 
    .margin({ 
      bottom: -15 
    }) 
    .onClick(() => { 
      if (this.isAutoCancel) { 
        this.cancel(); 
      } 
    }) 
    .visibility(this.showFlag) 
    // 定义进场出场转场动画效果 
    .transition(TransitionEffect.OPACITY.animation({ duration: anmDuration }) 
      .combine(TransitionEffect.translate({ y: 400 }))) 
  } 
 
  // 延迟关闭弹窗,让自定义的出场动画显示 
  cancel() { 
    this.showFlag = Visibility.Hidden 
    setTimeout(() => { 
      this.controller.close() 
    }, anmDuration) 
  } 
} 
 
@Entry 
@Component 
struct CustomDialogUser { 
  // 是否允许点击遮障层退出 
  @State isAutoCancel: boolean = true; 
  dialogController: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample({ isAutoCancel: this.isAutoCancel }), 
    autoCancel: this.isAutoCancel, 
    // 弹窗容器样式是否自定义 
    customStyle: true, 
    maskColor: 'rgba(255, 100, 255, 0)' 
  }) 
 
  build() { 
    Column() { 
      Text('click me') 
        .onClick(() => { 
          this.dialogController.open() 
        }) 
        .margin({ top: 700 }) 
    } 
    .width('100%').height('100%').margin({ top: 0 }) 
    .backgroundColor('#fff3ecec') 
  } 
}
展开全部
1楼回复于2024-06-17 10:31 未知归属地
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。