在 Mapbox 的导航视图上添加自定义按钮

Add custom button on Mapbox's navigation view

我正在使用 Mapbox 允许用户在不同位置之间导航。我正在使用文档中所述的基本导航功能 (https://www.mapbox.com/ios-sdk/navigation/examples/basic/)。这给了我如下的导航视图。

我想在视图底部添加一个自定义按钮。为此,我尝试了以下代码。

Directions.shared.calculate(options) { (waypoints, routes, error) in

    guard let route = routes?.first else {
        self.showAlertMessage("No possible routes detected")
        return
    }

    self.mapNavigationViewController = NavigationViewController(for: route)

    self.mapNavigationViewController.delegate = self

    self.present(self.mapNavigationViewController, animated: true, completion: {

        let customButton = UIButton()
        customButton.setTitle("Press", for: .normal)
        customButton.translatesAutoresizingMaskIntoConstraints = false
        customButton.backgroundColor = .blue
        customButton.contentEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)

        self.mapNavigationViewController.view.addSubview(customButton)

        customButton.bottomAnchor.constraint(equalTo: self.mapNavigationViewController.view.bottomAnchor, constant: 0).isActive = true
        customButton.leftAnchor.constraint(equalTo: self.mapNavigationViewController.view.leftAnchor, constant: 0).isActive = true
        customButton.rightAnchor.constraint(equalTo: self.mapNavigationViewController.view.rightAnchor, constant: 0).isActive = true

        self.mapNavigationViewController.view.setNeedsLayout()

    })
}

有了这个,我得到了如下按钮。

现在,接下来要做的是移动地图框的视图,使其底部与自定义按钮的顶部对齐。我怎样才能做到这一点?

要实现您的 objective,您必须更改库中实现的地图视图的底部约束。这样您就可以将其底部约束设置为等于 customButton

的顶部约束

查看您是否有权访问图书馆的地图视图或其底部限制。

我能够按照这个 Mapbox documentation.

完成任务