我正在使用 Mapbox 允许用户在不同位置之间导航。我正在使用文档 (https://www.mapbox.com/ios-sdk/navigation/examples/basic/) 中所述的基本导航功能。这给了我如下的导航 View 。
我想在 View 底部添加一个自定义按钮。为此,我尝试了以下代码。
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()
})
}
有了这个,我得到了如下按钮。
现在,接下来要做的是移动 map 框的 View ,使其底部与自定义按钮的顶部对齐。我怎样才能做到这一点?
最佳答案
我能够按照这个 Mapbox documentation 完成任务.
关于ios - 在 Mapbox 的导航 View 上添加自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53441668/