【问题标题】:Trigger NavigationLink through tap on Annotation in Mapkit通过点击 Mapkit 中的 Annotation 触发 NavigationLink
【发布时间】:2020-01-30 15:23:37
【问题描述】:

我想通过点击 Mapkit 中的注释来触发 NavigationLink。我可以设置一个布尔值,即某个注释被点击,但我无法通过它调用 SwiftUI 视图。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
            guard !(annotation is MKUserLocation) else {
                return nil
            }

            let identifier = "Annotation"
            var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

            if annotationView == nil {
                annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)

                annotationView?.canShowCallout = true

                annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
            } else {
                annotationView?.annotation = annotation
            }

            return annotationView
        }

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
            let selectedAssistance = self.parent.assistances.first {
                    $0.location.location?.coordinate == view.annotation?.coordinate
            }

            guard selectedAssistance != nil else {
                return
            }

            self.parent.selectedAssistance = selectedAssistance?.serverId ?? ""
            self.parent.presentSheet = true
        }

【问题讨论】:

    标签: swift mapkit swiftui mapkitannotation


    【解决方案1】:

    我做到了,通过在 ZStack 中调用我自己的 MapView,并在其后面放置了一个 NavLink,它在 Binding 上处于活动状态

    【讨论】:

    • 当我点击注释时,我的导航视图没有动画,知道为什么吗?
    猜你喜欢
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多