我试图做一个自定义注释。我制作了一个自定义注释类,在这里我设计了注释视图。我试图在Viewcontroller中调用viewForAnnotation中的类。当我运行应用程序时,它将显示基本视图。这是函数。如果您也想查看自定义注释类,请告诉我。

 func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {


    let reuseIdentifier = "CustomAnnotation"


    if (annotation.isKindOfClass(CustomAnnotation)) {
        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseIdentifier) as! CustomAnnotation!


        annotationView = CustomAnnotation(annotation: annotation, reuseIdentifier: reuseIdentifier)

        return annotationView
    }
        else {
            return nil
    }

}

最佳答案

func mapView(mapView:MKMapView,viewfornotation annotation:MKAnnotation)->MKAnnotationView?{
如果注释是MKUserLocation{
返回零
}

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView?.animatesDrop = true
        pinView?.canShowCallout = false
        pinView?.draggable = true
              }
    else {
    }

    return pinView
}

10-07 19:48
查看更多