ios - 在 Mapbox 的导航 View 上添加自定义按钮

标签 ios swift autolayout mapbox nslayoutconstraint

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

我想在 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()

    })
}

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

enter image description here

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

最佳答案

我能够按照这个 Mapbox documentation 完成任务.

关于ios - 在 Mapbox 的导航 View 上添加自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53441668/

相关文章:

iOS 8 - UIScrollView 不滚动

swift - 全宽 UICollectionViewCells、自动布局约束和旋转问题

ios - NEHotspotHelperCommand 命令不调用 PresentUI 或进行身份验证

ios - Xcode 10随机弹出 "The bundle identifier for XCode10Project.app couldn’ t被读取。”

ios - Realm addNotificationBlock 返回错误

swift - 试图 swift 概括

swift - 如何在 Cloud Firestore 中完成 WHERE IN 查询

swift - 一起使用 CocoaPods 和 @IBDesignable

ios - UICollectionView,只是让单元格适合宽度?

ios scrollview - subview 垂直越界