简体   繁体   中英

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!

Why can't you use standard NavigationLink as below?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM