我正在尝试在 MapView 上显示地名数组的结果。使用常规图钉不是问题:它们正常显示,点击时,详细信息单元格会显示地点名称。
for var t = 0;t<self.parties2.count;++t {
var placeLatitude:CLLocationDegrees = self.parties2[t].latitude
var placeLongitude:CLLocationDegrees = self.parties2[t].longitude
var placeLocation = CLLocationCoordinate2DMake(placeLatitude, placeLongitude)
var annotation = MKPointAnnotation()
annotation.coordinate = placeLocation
annotation.title = self.parties2[t].name
self.mapView.addAnnotation(annotation)
}
然后我用这个函数改变了图钉的外观:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
let identifier = "pin"
var view: MKAnnotationView
view = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
var image = UIImage(named: "symbol.png")
image = self.imageResize(image!, sizeChange: CGSizeMake(20, 20))
view.image = image
return view
}
(我使用 imageResize 函数调整 pin 图像的大小)
此函数成功地改变了 pin 的外观:它确实变成了所需的图像。但是,单击这些图像不再显示详细信息。
最佳答案
好的,我只需要将 pinView.canShowCallout = true 添加到我的代码中,我假设它默认为 true,因为原始 pin 不需要它。
关于ios - 单击时 MapView 自定义图钉不显示详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32989480/