【HarmonyOS NEXT】如何实现底部弹窗动画

本文介绍了如何在ArkTS中模仿Android中的XML动画,实现对话框如华为帐号注册时的弹起和收回效果,通过`CustomDialog`组件和自定义动画函数来控制对话框的显示和隐藏过程。
摘要由CSDN通过智能技术生成

【关键字】

ArkTS / dialog / 弹起 / 收回 / 动画

【问题描述】

ArkTS如何实现类似Android通过在xml里设置<set><translate>属性,来控制dialog弹起收回的动画效果?类似首次使用华为帐号,dialog底部弹起及收回的动画。

【解决方案】

请参考如下代码:

let anmDuration: number = 800;

// 弹窗交互
@CustomDialog
struct CustomDialogExample {

controller: CustomDialogController = new CustomDialogController({
builder: CustomDialogExample({}),
autoCancel:false
})

@State showFlag: Visibility = Visibility.Visible;
@State isAutoCancel: boolean = false;

build() {
Column() {
Text('点我关闭弹窗').fontSize(20).margin({ top: 10, bottom: 10 })
.backgroundColor('#FFFFFF')
.textAlign(TextAlign.Center)
.height(200)
.width('100%')
.margin({top:600})
.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: 100})))
}

cancel(){
this.showFlag=Visibility.Hidden
setTimeout(()=>{
this.controller.close()
}, anmDuration)
}
}
@Entry
@Component
struct CustomDialogUser {
@State isAutoCancel: boolean = false;

dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogExample({ isAutoCancel: this.isAutoCancel }),
autoCancel: this.isAutoCancel,
customStyle:true
})

build() {
Column() {
Button('click me')
.onClick(() => {
this.dialogController.open()
})
}.width('100%').height('100%').margin({ top: 5 })
.onClick(()=>{
})
}
}

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-promptaction-0000001821000749

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值