【发布时间】:2015-04-18 08:23:27
【问题描述】:
我正在尝试在 MKMapView 中的引脚上实现自定义注释视图。另一个用户给了我这个函数来生成一个自定义的 MKPinAnnotationView。 https://stackoverflow.com/users/3845091/zisoft
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is PinAnnotation {
let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
pinAnnotationView.pinColor = .Purple
pinAnnotationView.draggable = true
pinAnnotationView.canShowCallout = true
pinAnnotationView.animatesDrop = true
let deleteButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
deleteButton.frame.size.width = 44
deleteButton.frame.size.height = 44
deleteButton.backgroundColor = UIColor.redColor()
deleteButton.setImage(UIImage(named: "trash"), forState: .Normal)
pinAnnotationView.leftCalloutAccessoryView = deleteButton
return pinAnnotationView
}
return nil
}
我会将我想要的地图参数和我想要自定义的注释传递给函数。即mapView(myMap, viewForAnnotation: point)
这一切都很好,也很有意义,但是,当我尝试使用 map.addAnnotation(mapView(myMap, viewForAnnotation: point)) 将 MKPinAnnotationView 添加到地图时,它会出错,提示数据类型无效。有人知道如何使用自定义视图在地图上物理渲染图钉吗?
简单的解决方案总是最好的。
谢谢!
【问题讨论】:
标签: ios iphone swift annotations maps