文档开发者中心
我的
|

HarmonyOS 5

CustomDialog的CustomDialogController设置了offset: { dx: 0, dy: -100 },alignment: DialogAlignment.Bottom 弹出的时候不是从offest弹出

CustomDialog的CustomDialogController设置了offset: {   dx: 0, dy: -100 },alignment: DialogAlignment.Bottom 弹出的时候不是从offest的位置弹出,而是从最底下屏幕边框弹出。

这个需要怎么优化下呢?

点赞
收藏
回复
11
分享
举报
浏览188 发布于2025-02-06 09:54北京
全部评论
最多点赞
最新发布
最早发布
开发者您好,能提供一个最小demo吗?
10
1楼回复于2025-02-07 03:01 来自广东
  • Harmony实习生
    let anmDuration: number = 800; // 弹窗交互 @CustomDialog export struct CustomDialogExample { @State showFlag: Visibility = Visibility.Visible; @State isAutoCancel: boolean = false; controller: CustomDialogController = new CustomDialogController({ builder: CustomDialogExample({}), autoCancel:false }) build() { Column() { Text('我是内容').fontSize(20).margin({ top: 10, bottom: 10 }) .backgroundColor('#FFFFFF') .textAlign(TextAlign.Center) .height(200) .width('100%') .onClick(()=>{ this.cancel(); }) } .width('100%') .height('100%') .justifyContent(FlexAlign.End) .onClick(()=>{ if(this.isAutoCancel){ this.cancel(); } }) .visibility(this.showFlag) // 定义进场出场转场动画效果 .transition( TransitionEffect .move(TransitionEdge.BOTTOM) .animation({ duration: 3000, curve: Curve.FastOutSlowIn })) } // 延迟关闭弹窗,让自定义的出场动画显示 cancel(){ this.showFlag=Visibility.Hidden setTimeout(()=>{ this.controller.close() }, anmDuration) } } import { CustomDialogExample } from './CustomDialogExample'; @Component export struct CustomDialogUser { // 是否允许点击遮障层退出 @State isAutoCancel: boolean = true; dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialogExample({ isAutoCancel: this.isAutoCancel }), autoCancel: this.isAutoCancel, // 弹窗容器样式是否自定义 customStyle: true, offset: { dx: 0, dy: -200 } }) build() { Column() { Button('click me') .onClick(() => { this.dialogController.open() }) } .width('100%') .height('100%') .margin({ top: 5 }) } }
    展开全部
    2025-02-07 06:54 来自北京
  • Harmony实习生
    加了这个.animation({ duration: 3000, curve: Curve.FastOutSlowIn })时间就可以看出来,不加的话,看不出来,但是需要加时间,否则动画太快了。
    2025-02-07 06:55 来自北京
  • 攻城狮回复Harmony实习生
    开发者您好,offset应该是弹窗的最终位置,这边是想要调整弹窗的弹出位置吗?
    2025-02-07 08:43 来自广东
  • 展开剩余7条回复
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要提问题

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