HarmonyOS 鸿蒙Next CustomDialog 怎么可以关闭closeAnimation的动画 HarmonyOS 鸿蒙Next 默认关闭动画有缩放效果如何取消

发布于 1周前 作者 wuwangju 来自 鸿蒙OS

HarmonyOS 鸿蒙Next CustomDialog 怎么可以关闭closeAnimation的动画
HarmonyOS 鸿蒙Next 默认关闭动画有缩放效果如何取消 CustomDialog 怎么可以关闭 closeAnimation 的动画?默认的关闭动画有缩放动画效果,我现在不需要这个缩放动画效果。

5 回复

// xxx.ets

@CustomDialog struct CustomDialogExample { controller?: CustomDialogController cancel: () => void = () => { } confirm: () => void = () => { }

build() { Column() { Text(‘这是自定义弹窗’) .fontSize(30) .height(100) Button(‘点我关闭弹窗’) .onClick(() => { if (this.controller != undefined) { this.controller.close() } }) .margin(20) } } }

@Entry @Component struct CustomDialogUser { dialogController: CustomDialogController | null = new CustomDialogController({ builder: CustomDialogExample({ cancel: () => { this.onCancel() }, confirm: () => { this.onAccept() } }), cancel: this.existApp, autoCancel: true, alignment: DialogAlignment.Center, closeAnimation:{}, offset: { dx: 0, dy: -20 }, customStyle: false, cornerRadius: 20, width: 300, height: 200, borderWidth: 1, borderStyle: BorderStyle.Dashed, //使用borderStyle属性,需要和borderWidth属性一起使用 borderColor: Color.Blue, //使用borderColor属性,需要和borderWidth属性一起使用 backgroundColor: Color.White, shadow: ({ radius: 20, color: Color.Grey, offsetX: 50, offsetY: 0 }), })

// 在自定义组件即将析构销毁时将dialogController置空 aboutToDisappear() { this.dialogController = null // 将dialogController置空 }

onCancel() { console.info(‘Callback when the first button is clicked’) }

onAccept() { console.info(‘Callback when the second button is clicked’) }

existApp() { console.info(‘Click the callback in the blank area’) }

build() { Column() { Button(‘click me’) .onClick(() => { if (this.dialogController != null) { this.dialogController.open() } }).backgroundColor(0x317aff) }.width(‘100%’).margin({ top: 5 }) } }

看着默认的效果并没有缩放效果

更多关于HarmonyOS 鸿蒙Next CustomDialog 怎么可以关闭closeAnimation的动画 HarmonyOS 鸿蒙Next 默认关闭动画有缩放效果如何取消的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


您的是居住,我的是是buttom,是不是这个问题。不过在消失的时候,我还加了:

.transition( TransitionEffect .move(TransitionEdge.BOTTOM) .animation({ duration: 300, curve: Curve.FastOutSlowIn }) )


给Dialog里面的根布局加了动画,
private dialogController: CustomDialogController | null = new CustomDialogController({
  builder: ShowDialogView({}),
  //需要自定义样式
  customStyle: true,
  alignment: DialogAlignment.Bottom,
  offset: {
    dx: 0,
    dy: -98
  },
  maskColor: Color.Transparent,
  maskRect: {
    x: 0,
    y: 98,
    width: '100%',
    height: 750
  },
  showInSubWindow: false,
  backgroundColor: Color.Transparent,
  isModal: false,
  autoCancel: true,
  openAnimation: undefined,
  closeAnimation: undefined,
  cancel: () => {
   
  },
  onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
    if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
     
    }
    if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {

    }
  }
});

把你的问题代码发出来看下呢

在HarmonyOS(鸿蒙)系统中,如果你想在自定义的CustomDialog中关闭关闭动画(closeAnimation)的缩放效果,可以通过以下方式实现:

首先,你需要获取到CustomDialogWindow对象。通过getWindow()方法,你可以访问到对话框的窗口属性。

接下来,使用setWindowAnimations(0)方法将动画资源ID设置为0,这通常意味着禁用动画。但需要注意的是,直接禁用所有动画可能不是最佳实践,因为它会同时禁用打开和关闭动画。

为了更精细地控制,你可以尝试以下步骤:

  1. 自定义一个空的动画资源文件(例如,在res/anim/目录下创建一个no_animation.xml,内容为空或仅包含一个无操作的<set>标签)。
  2. 在创建或显示CustomDialog之前,通过getWindow().setWindowAnimations(R.anim.no_animation)应用这个自定义的动画资源。
  3. 由于你只想禁用关闭动画,而保持打开动画,可能需要进一步定制动画资源,但这在鸿蒙系统中可能不如在Android中灵活。因此,一个简单的方法是仅使用上述的空动画资源来禁用所有动画,然后在逻辑上通过其他方式(如延迟关闭等)模拟无动画的关闭效果。

然而,根据鸿蒙系统的API设计,可能并不直接支持仅禁用关闭动画而不影响打开动画。如果上述方法不适用,你可能需要查阅鸿蒙系统的最新开发文档或API指南,以寻找更具体的解决方案。

如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html

回到顶部