我使用mapbox允许用户在不同位置之间导航。我正在使用文档中所述的基本导航功能(
https://www.mapbox.com/ios-sdk/navigation/examples/basic/
)。这给了我下面的导航视图。
我想在视图的底部添加一个自定义按钮。为此,我尝试了以下代码。
directions.shared.calculate(options)(waypoints,routes,error)in
guard let route=路线?首先,否则{
self.showAlertMessage(“未检测到可能的路由”)
返回
}
self.mapNavigationViewController=导航视图控制器(用于:路由)
self.mapNavigationViewController.delegate=自己
self.present(self.mapNavigationViewController,动画:真,完成:{
让customButton=uiButton())
customButton.settitle(“按”,用于:.normal)
customButton.translatesAutoResizingMaskinToConstraints=false
customButton.backgroundColor=.blue
customButton.contentedgeinsets=uiedgeinsets(上:10,左:20,下:10,右:20)
self.mapNavigationViewController.view.addSubView(自定义按钮)
customButton.bottomAnchor.constraint(等于:self.mapNavigationViewController.view.bottomAnchor,常量:0)。isActive=true
customButton.leftAnchor.constraint(等于:self.mapNavigationViewController.view.leftAnchor,常量:0)。isActive=true
customButton.rightAnchor.constraint(等于:self.mapNavigationViewController.view.rightAnchor,常量:0)。isActive=true
self.mapNavigationViewController.view.setNeedsLayout()。
})
}
< /代码>
有了这个,我得到了下面的按钮。

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

我想在视图的底部添加一个自定义按钮。为此,我尝试了以下代码。
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()
})
}
有了这个,我得到了下面的按钮。

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