Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The picture will disappear in 10-15 seconds. SwiftUi

How to make the picture disappear 15 seconds after opening the application?

which method should i use? Animation or some kind of function?

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

struct Img: View {
    var body: some View {
        
        VStack {
            
            Image(systemName: "photo.fill")
                .resizable()
                .scaledToFit()
                .frame(width: 200, height: 200)
            
        }
    }
}

after 10 -15 seconds after opening the application, the picture disappears and does not appear. After I reopen the application, there will be a picture again and it will disappear after 10 – 15 seconds …

Help me if you know how to do this, I will be grateful for any help

>Solution :

You can use an animation delay.

This example will show the image for 15 seconds, then fade out. When the application is force quit and opened again, the same thing happens again:

struct Img: View {
    @State private var isImageVisible = true

    var body: some View {
        VStack {
            Image(systemName: "photo.fill")
                .resizable()
                .scaledToFit()
                .frame(width: 200, height: 200)
                .opacity(isImageVisible ? 1 : 0)
                .animation(.default.delay(15), value: isImageVisible)
        }
        .onAppear {
            isImageVisible = false
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading