是否可以使 MGLPolyLine 可触摸/可选择/具有用户交互?在我的项目中,用户需要触摸折线。有 this question之前问过,但它已经过时了大约 2 年。他们(MapBox)更新了吗?
最佳答案
我刚回来查看,看起来这已经实现了,但我不确定是哪个 Mapbox 版本推出的。
如果您看一下简单的 Mapbox 示例,Annotation Models ,它演示了 MGLPolyline 和间隔的圆形注释,您可以对提供的代码进行简单的修改并亲自查看。演示看起来像这样:
如果您查看 viewController 代码,请在折线创建下方添加几行:
let polyline = CustomPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
polyline.title = "Polyline" // New line
polyline.subtitle = "Pretty Poly". // New line
// Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method.
polyline.color = .darkGray
现在您可以点按并查看基本标注:
这个例子子类化了 MGLPolyline (CustomPolyline),所以它的外观可以稍微改变,但不会改变任何关于可点击性的东西。
关于swift - 是否可以使 MGLPolyLines 可选? - swift , map 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54586620/