中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
组件的某些通用属性变化时,可以通过属性动画实现渐变过渡效果,提升用户体验。支持的属性包括width、height、backgroundColor、opacity、scale、rotate、translate等。 说明:从API Version 7开始支持。开发语言ets. 示例代码:
@Entry @Component struct AttrAnimation { @State widthSize: number = 200; @State heightSize: number = 100; @State fontSize: number = 20; @State attrFlag: boolean = true; build() { Column() { Row(){ Text(this.attrFlag ? '点击缩小':'点击变大').fontSize(this.fontSize) }.onClick(() => { if (this.attrFlag) { this.widthSize = 100 this.heightSize = 50 } else { this.widthSize = 200 this.heightSize = 100 } this.attrFlag = !this.attrFlag }).width(this.widthSize) .height(this.heightSize) .backgroundColor(0x317aff) .justifyContent(FlexAlign.Center) .animation({ duration: 2000, // 动画时长 tempo:2,//动画播放速度 curve: Curve.EaseOut, // 动画曲线 delay: 500, // 动画延迟 iterations: 1, // 播放次数 playMode: PlayMode.Normal // 动画模式 }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }
示例效果:
微信扫码分享