Koushik Mudi
Koushik Mudi

Reputation: 31

How to push a view for tap gesture on a View in SwiftUI?

I want to push a View when I tap on an Image. My Code so far:

struct Home: View {
    var body: some View {
        NavigationView {
            VStack {
                Image("image")
                    .onTapGesture {
                   //navigation code here
                }
                Text("Tap on image to find details")
            }
        }
    }
}

How to achieve that navigation? Thanks!

Upvotes: 2

Views: 4713

Answers (1)

Asperi
Asperi

Reputation: 257693

Why can't you use standard NavigationLink as below?

NavigationView {
    VStack {
        NavigationLink(destination: SomeDestinationViewHere()) {
            Image("image")
        }
        Text("Tap on image to find details")
    }
}

Upvotes: 5

Related Questions