如何显示一秒钟的图像? SWIFTUI 界面

How to display an image for one second? SWIFTUI

我想在玩家达到目标时显示一秒钟的图像。我考虑过发出警报,但它会减慢游戏速度。我只想让图像在屏幕顶部停留一秒钟,然后消失,直到下一个成就。

示例代码如下:

var TapNumber = 0

func ScoreUp() {

TapNumber += 1

 if TapNumber == 100 {
 showImage()
 }
}


func showImage() {
 // this is the function I want to create but. I do not know how
 show image("YouEarnedAPointImage") for one second
}

这是一个可能的方法演示

struct DemoShowImage1Sec: View {
    @State private var showingImage = false
    var body: some View {
        ZStack {
            VStack {
                Text("Main Content")
                Button("Simulate") { self.showImage() }
            }
            if showingImage {
                Image(systemName: "gift.fill")
                    .resizable()
                    .frame(width: 100, height: 100)
                    .background(Color.yellow)
            }
        }
    }

    private func showImage() {
        self.showingImage = true
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            self.showingImage = false
        }
    }
}