写点什么

【HarmonyOS】鸿蒙图片淡入淡出切换

作者:zhongcx
  • 2024-10-11
    广东
  • 本文字数:507 字

    阅读完需:约 2 分钟

点击按钮时,应该会在两张图片之间切换,并应用淡入淡出的动画效果。注意只有用 if 时才会生效,用.visibility()只有显示的时候生效,隐藏不生效。

@Entry@Componentstruct Page09 {  @State isShowImage1: boolean = false;  base64Str: string =    'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAA...'  @State idAnim: string = "idAnim"   build() {    Column() {      Button('切换图片 淡入淡出').onClick(() => {        this.isShowImage1 = !this.isShowImage1      })      Stack() {        if (this.isShowImage1) {          Image($r("app.media.app_icon"))            .width('100%')            .height('100%')            .transition(TransitionEffect.OPACITY.animation({ duration: 600, curve: Curve.Sharp }))        } else {          Image(this.base64Str)            .width('100%')            .height('100%')            .transition(TransitionEffect.OPACITY.animation({ duration: 600, curve: Curve.Sharp }))        }      }.width('200lpx').height('200lpx')    }    .height('100%')    .width('100%')  }}
复制代码


用户头像

zhongcx

关注

还未添加个人签名 2024-09-27 加入

还未添加个人简介

评论

发布
暂无评论
【HarmonyOS】鸿蒙图片淡入淡出切换_zhongcx_InfoQ写作社区