简体   繁体   English

如何在 SwiftUI 中的视图上推送点击手势视图?

[英]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?为什么不能使用如下标准 NavigationLink?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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