如何在swift中为自定义注释添加正确的标注附件?

时间:2016-05-19 07:48:51

标签: ios swift mkmapview mkannotation

我有以下自定义注释类:

for i in 0..<allLocations.count{
            //Add an annotation
            let l: Location = self.allLocations[i] as! Location
            let coordinates = CLLocationCoordinate2DMake(l.latitude as Double, l.longitude as Double)
            let annotation = LocationAnnotation(title: l.name, coordinate: coordinates, location: l)
            mapView.addAnnotation(annotation)
        }

我正在将注释加载到这样的地图视图中:

Deprecation Warning: Firebase Hosting configuration should be moved under "hosting" key.

如何在地图视图中的注释右侧添加(i)信息按钮。还有一种简单的动画方法吗?

感谢。

1 个答案:

答案 0 :(得分:2)

试试这个:

这里实现了MKAnnotation协议的“Sample”类。您需要根据注释类型进行调整。

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "Sample"

if annotation.isKindOfClass(Sample.self) {
    if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) {

 // Reuse Annotationview

        annotationView.annotation = annotation
        return annotationView
    } else {

 // Create Annotation

        let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:identifier)
        annotationView.enabled = true
        annotationView.canShowCallout = true

 // Here I create the button and add in accessoryView

        let btn = UIButton(type: .DetailDisclosure)
        annotationView.rightCalloutAccessoryView = btn
        return annotationView
    }
}
return nil
}