ios - Swift 中的 MapBox - 允许标记的注释具有链接到 View 的按钮

标签 ios swift mapbox mapbox-marker

我已经设置了一个带有选项卡式 map View (选项卡 1 上的 map )的简单应用程序,该应用程序使用 SwiftyJSON 和 Alamofire 从服务器上的 json 文件中读取信息(点信息存储在 MySQL 中)。这些点被加载到 map 中。我想做的是在注释中添加一个按钮,该按钮输出到不同的 View 选项卡并传递点的 ID。

我还没有尝试过任何东西,因为我不知道从哪里开始,文档也​​没有提到任何类似的东西。

如何向 map 点注释添加导出?

最佳答案

当您点击图钉时,会出现带有标题和/或副标题的标注。您需要为此标注添加左右标注附件 View 。您可以通过遵循 MGLMapViewDelegate 并实现以下方法来做到这一点:

func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
        return true
}

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
    ...your code here...
    let deleteButton = UIButton(type: .custom)
    deleteButton.tag = 100
}

func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
    ...your code here...
    let infoButton = UIButton(type: .custom)
    infoButton.tag = 101
}

func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
    ...your code here...
    switch control.tag {
    case 100:
       // do some delete stuff
    case 101:
       // do some info stuff
    default:
       break 
}

显示实际用法的 MapBox 示例在这里: MapBox example .这个例子没有 segue,但你只需点击按钮而不是 UIAlert 来触发 segue。

关于ios - Swift 中的 MapBox - 允许标记的注释具有链接到 View 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41944730/

相关文章:

javascript - setFeatureState 不更新 Mapbox 中的值

ios - 如何加载mapbox而不将其添加到 View 层次结构?

ios - 使用 Web 服务对远程数据库实现用户身份验证

objective-c - 从横向模式启动时,iAd 不适合宽度

ios - 设置分组 UITableView 中选定 UITableViewCell 的背景

swift - Firebase ref.removeAllObservers() 是否也递归删除子观察者?

ios - 如何在删除 IOS 应用程序时删除文件?

ios - CallState 永远不会是 CTCallStateDisconnected?

xcode - Swift & NSTableView - 只需选择一行

javascript - map.on ('click' ) 是否干扰 Bootstrap 模式?