我已经设置了一个带有选项卡式 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/