【每日学点HarmonyOS Next知识】对话框去掉圆角、数组拼接、自定义对话框依附某个控件、平移动画、页面栈管理

发布于:2025-03-13 ⋅ 阅读:(29) ⋅ 点赞:(0)
1、 HarmonyOS CustomDialog怎么去掉左右和底部的透明以及圆角?

CustomDialog怎么去掉左右和底部的透明以及圆角

设置customStyle为true即可开启使用自定义样式。设置borderRadius为0去掉圆角属性。

属性用法参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-methods-custom-dialog-box-V5

2、HarmonyOS 数组拼接问题 在一个数组中前置拼接另一个数组?

插入的是数组元素时使用concat

let  list: Array<number> = [1]
let  list2: Array<number> = [2]
let list3 = list.concat(list2)
console.log(list3.toString());
3、HarmonyOS 自定义弹窗dialog怎么设置依附于某个组件下面?

想要实现dialog弹窗依附于Toolbar下方。怎么设置才能实现。用的是CustomDialog

  1. 依照现在开放的 CustomDialog 的API,无法实现依附效果。
  2. 可以尝试使用 bindContextMenu 。

参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-menu-V5
在这里插入图片描述

4、HarmonyOS 平移动画?

给图片添加平移动画时,从指定的起始坐标点,到终点时,怎么设置起始点?

通过.position可设置他的起始位置,使用.translate可以设置组件转场时的平移效果比如 得要求起始位置(100,16)平移到(220,16), 看下下面得代码,使用position将组件定位在(100,16),然后设置他的平移效果为x轴方向平移120,y轴方向平移0,就到了(220,16)这个位置

参考以下代码:

Image($r('app.media.app_icon')).width(30).height(30)
  .translate({ x: 120, y: 0 })// x轴方向平移120,y轴方向平移0
  .transition(TransitionEffect.SLIDE.animation({
    duration: 1200,
    curve: Curve.EaseOut,
    iterations: 1,
    delay: 100,
    playMode: PlayMode.Normal,
    onFinish: () => {
      // LogUtils.info(this.TAG,`---------动画完成`)
    }
  }))
  .position({
    x: 100,
    y: 16
  })
5、HarmonyOS @ohos.router不支持页面栈的自主管理?

在router跳转的时候可以使用router.replaceUrl()方法使得目标页去替换并销毁当前页,也可以使用使用ArkUI的Navigation已支持支持HarmonyOS页面栈管理。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navigation-V5

Navigation组件是路由导航的根视图容器,一般作为Page页面的根容器使用,其内部默认包含了标题栏、内容区和工具栏,其中内容区默认首页显示导航内容(Navigation的子组件)或非首页显示(NavDestination的子组件),首页和非首页通过路由进行切换。


网站公告

今日签到

点亮在社区的每一天
去签到