首页 > 移动开发 > ANDROID > 【HarmonyOS】鸿蒙图片淡入淡出切换
【HarmonyOS】记录淡入淡出切换控件内图片的方法.transition(TransitionEffect.OPACITY)

注意只有用 if 时才会生效,用.visibility()只有显示的时候生效,隐藏不生效。
@Entry @Component struct Page09 { @State isShowImage1 : boolean = false ; base64Str : string = build ( ) { Column ( ) { Button ( '切换图片 淡入淡出' ) . onClick ( ( ) => { this . isShowImage1 = ! this . isShowImage1 } ) Stack ( ) { if ( this . isShowImage1 ) { Image ( $r ( ".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%' ) } }
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24984661/viewspace-3107417/ ,如需转载,请注明出处,否则将追究法律责任。