合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
小吧主问题描述:
二级浮层的出场动画实现。

解决方案:
以下示例代码可以实现进场由下到上,出场由上到下
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')
}
}我要发帖子
HarmonyOS scrollToIndex不能设置动画时间(API12+)
HarmonyOS Scroller.fling小速度值时动画为何不流畅?(API12+)
HarmonyOS 组件从边角到全屏的动画(API12+)
HarmonyOS Next应用开发如何实现球状标签动画?类似3D单词星球样式
【ArkUI弹出框系列】〇:动画全面解析:从基础动画能力到高阶动画效果的实现
如何实现8字形轨迹的三球动画
如何实现悬浮按钮效果
【ArkUI动画系列】二:ArkUI基础动画能力之属性动画
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功