1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * 为图片添加事件 onClick以及onFinish 18 */ 19@Entry 20@Component 21struct ImageExample3 { 22 private imageOne: Resource = $r('app.media.earth'); 23 private imageTwo: Resource = $r('app.media.star'); 24 private imageThree: Resource = $r('app.media.moveStar'); 25 @State src: Resource = this.imageOne 26 @State src2: Resource = this.imageThree 27 build(){ 28 Column(){ 29 // 为图片添加点击事件,点击完成后加载特定图片 30 Image(this.src) 31 .width(100) 32 .height(100) 33 .onClick(() => { 34 this.src = this.imageTwo 35 }) 36 37 // 当加载图片为SVG格式时 38 Image(this.src2) 39 .width(100) 40 .height(100) 41 .onFinish(() => { 42 // SVG动效播放完成时加载另一张图片 43 this.src2 = this.imageOne 44 }) 45 }.width('100%').height('100%') 46 } 47}