[英]Mapbox iOS SDK 3.1 How to make Annotation Callout sticky
i just started developing in iOS.我刚开始在 iOS 中开发。 So sorry if the problem seems to be trivial:
如果问题似乎微不足道,那么抱歉:
I load several markers / annotations via SwiftyJSON from an API and display those on a Mapbox MapView.我通过 API 中的 SwiftyJSON 加载了几个标记/注释,并将它们显示在 Mapbox MapView 上。 When clicking on the annotation the callout is triggered.
单击注释时,会触发标注。 - this works fine and easy as hell.
- 这工作得很好,很容易。 The Problem: I'd like to center the mapView on the marker / annotation and callout, or move the camera to show them in the center, zoomed in. Whenever I use something like this:
问题:我想将 mapView 放在标记/注释和标注上,或者移动相机以将它们显示在中心,放大。每当我使用这样的东西时:
let camera = MGLMapCamera(lookingAtCenterCoordinate: annotation.coordinate, fromDistance: 1000, pitch: 0, heading: 0)
mapView.setCamera(camera, withDuration: 2, animationTimingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
or或者
mapView.setCenterCoordinate(annotation.coordinate, zoomLevel: 15, animated: true)
The callout just stays in the same position.标注只是保持在相同的位置。 What I would like to achieve is, that it's displayed sticky on top of the annotation / marker.
我想要实现的是,它在注释/标记的顶部显示粘性。
This is my complete code for this part (building of the annotations in viewdidload not included:这是我这部分的完整代码(不包括在 viewdidload 中构建注释:
func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? {
var annotationImage = mapView.dequeueReusableAnnotationImageWithIdentifier("marker_live")
if annotationImage == nil {
// Leaning Tower of Pisa by Stefan Spieler from the Noun Project
var image = UIImage(named: "marker_live")!
image = image.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, 0, image.size.height/2, 0))
annotationImage = MGLAnnotationImage(image: image, reuseIdentifier: "marker_live")
}
return annotationImage
}
func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
print("tap on annotation")
mapView.selectAnnotation(annotation, animated: true)
return true
}
func mapView(mapView: MGLMapView, calloutViewForAnnotation annotation: MGLAnnotation) -> UIView? {
return CustomCalloutView(representedObject: annotation)
}
func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) {
print("Tapped the callout for: \(annotation.title!)")
self.performSegueWithIdentifier("PlaylistFromMap", sender: annotation.title!)
mapView.deselectAnnotation(annotation, animated: true)
}
I also thought about using a completion handler, but didn't understood how it works.我也考虑过使用完成处理程序,但不明白它是如何工作的。 Help much appreciated!
非常感谢帮助!
The position of a callout view currently cannot be updated after it has been displayed, but this is a feature we're looking to add in v3.3.0.当前标注视图的位置在显示后无法更新,但这是我们希望在 v3.3.0 中添加的功能。
To open the callout after a setCamera:
or setCoordinate:
animation, use the variants of those methods that includes a completion handler and then selectAnnotation:
there.要在
setCamera:
或setCoordinate:
动画之后打开标注,请使用包含完成处理程序的这些方法的变体,然后selectAnnotation:
那里selectAnnotation:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.