【鸿蒙ArkUI实战开发】基于ArkUI的动效能力

场景一:使用属性动画完成登录的动效

效果图

方案

控制输入框的宽度和显隐状态实现第一段动画,输入框的缩放动画完成后onFinish隐藏输入框,同时展示加载动画。

核心代码


Column() {

LoadingProgress()

.width(60)

.height(60)

}

.width(80)

.height(80)

.borderRadius(40)

.backgroundColor(Color.White)

.justifyContent(FlexAlign.Center)

.position({ x: 90, y: 0 })

.opacity(this.loadingOpacity)

.animation({

duration: 300,

playMode: PlayMode.Alternate,

expectedFrameRateRange: {

min: 20,

max: 120,

expected: 90,

}

})

TextInput({ text: $$this.username, placeholder: "请输入用户名", controller: this.controller })

.placeholderColor("#D4D3D1")

.backgroundColor("#ffffff")

.width(this.inputWidth)

.height(40)

.visibility(this.inputVisibility)

.border({

width: {

left: 0,

right: 0,

top: 0,

bottom: 1

},

color: { bottom: Color.Gray },

radius: { topLeft: this.inputRadius, topRight: this.inputRadius },

style: { bottom: BorderStyle.Solid }

})

.id("username")

.defaultFocus(true)

.animation({

duration: 300,

playMode: PlayMode.Alternate,

onFinish: () => {

if (this.isLogin) {

this.inputVisibility = Visibility.Hidden;

this.loadingOpacity = 1;

this.isLogin = false;

}

},

expectedFrameRateRange: {

min: 20,

max: 120,

expected: 90,

}

})

场景二:使用Navigation完成不同的转场动画。

效果图

方案

配置完自定义的转场动画,然后将name指定的NavDestination页面信息入栈。

核心代码


// PageOne.ets

Button('动画1', { stateEffect: true, type: ButtonType.Capsule })Button('动画0', { stateEffect: true, type: ButtonType.Capsule })

.width('80%')

.height(40)

.margin(20)

.onClick(() => {

CustomTransition.getInstance().registerNavParam(this.pageId, (isPush: boolean, isExit: boolean) => {

}, (isPush: boolean, isExit: boolean)=> {

}, (isPush: boolean, isExit: boolean) => {

}, 200);

this.pageInfos.pushPathByName('pageTwo', null) //将name指定的NavDestination页面信息入栈,传递的数据为param

})

Button('动画1', { stateEffect: true, type: ButtonType.Capsule })

.width('80%')

.height(40)

.margin(20)

.onClick(() => {

CustomTransition.getInstance().registerNavParam(this.pageId, (isPush: boolean, isExit: boolean) => {

this.myScale = isExit ? 1 : 1.2;

}, (isPush: boolean, isExit: boolean)=> {

this.myScale = isExit ? 1.2 : 1;

}, (isPush: boolean, isExit: boolean) => {

this.myScale = 1;

}, 200);

this.pageInfos.pushPathByName('pageThree', null) //将name指
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值