【问题标题】:Mapbox Navigation SDK integration with SwiftUI 5Mapbox Navigation SDK 与 SwiftUI 5 的集成
【发布时间】:2020-03-29 17:53:06
【问题描述】:
import SwiftUI
import Mapbox
import MapboxAnnotationExtension
import MapboxDirections
import MapboxCoreNavigation
import MapboxNavigation

/****** some classes for different types of annotations

struct MapboxRepresent: UIViewRepresentable {

................

   class Coordinator: NSObject, MGLMapViewDelegate {

        func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {
            let navigationViewController = NavigationViewController(for: directionsRoute!)
            navigationViewController.modalPresentationStyle = .fullScreen
            !!!! -> present(navigationViewController, animated: true, completion: nil)
// here is error - Use of unresolved identifier 'present'
        }
   }

.................

}

此代码正常工作;它显示地图和所有注释。 tap 的功能仅用于测试。由于我是 SwiftUI5 的新手,我无法理解如何解决这个问题。

【问题讨论】:

  • present 是一个UiViewController 方法。您名为 Coordinator 的对象继承自 NSObjectMGLMapViewDelegate 但不是 UIViewController 因此未解析的标识符。它不知道present 方法是什么,因为它确实不应该。
  • 我知道。问题是我不明白我必须在哪个地方激活导航

标签: ios navigation mapbox


【解决方案1】:

您不能在 SwiftUI 视图中定义的协调器内调用 .present。您需要创建一个代表 Mapbox NavigationViewController 的新 SwiftUI 视图。然后,您可以使用 .sheet 打开该 Swift 导航视图的模式。看看这个tutorial,了解如何使用 SwiftUI 将 Mapbox 地图和导航带到 iOS 应用程序。

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2020-06-04
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多