自动显示注释标题

时间:2015-01-28 17:00:03

标签: swift mkmapview mkannotation

我试图自动显示注释标题,而不是点击显示。我使用下面的代码来显示注释并使其在地图上居中。

self.ann.setCoordinate(currentLocation2D)
self.ann.title = "Title"
self.ann.subtitle = "Subtitle"
self.mapView.addAnnotation(self.ann);

self.span = MKCoordinateSpanMake(0.005, 0.005)
self.region = MKCoordinateRegion(center: currentLocation2D, span: self.span)
self.mapView.setRegion(self.region, animated: true)

当我点按注释但无法自动显示注释时,我会看到titlesubtitleCalloutAccessoryView

2 个答案:

答案 0 :(得分:27)

您可以使用selectAnnotation来使用它,并使用mapview.annotations数组,其中包含您在地图上拥有的所有annotations

let yourAnnotationAtIndex = 0
mapView.selectAnnotation(mapView.annotations[yourAnnotationAtIndex], animated: true)

答案 1 :(得分:1)

mapView.selectAnnotation(mapView.annotations[0], animated: true)