Swift MKMapView 的自定义标注

Swift Custom Callout for MKMapView

我正在为地图视图实现自定义标注视图。我得到这个输出

我使用的是注释视图

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

     let reuseId = "mapPin"
   var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? CustomCalloutView
    if anView == nil {
    anView=CustomCalloutView(annotation: annotation,reuseIdentifier:reuseId)
        anView!.image = UIImage(named:"mappin.png")
        let button : UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
        button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        anView!.rightCalloutAccessoryView=button
     //anView!.addSubview(viewC)
    mapViewControl.addAnnotation(annotation)
    }
    else {
        anView!.annotation = annotation
    }

    return anView
}

并弹出标注视图

    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!){
    var viewC:UIView=UIView(frame: CGRectMake(0, 0, 50, 50))
    viewC.backgroundColor = UIColor.blackColor()

   view.addSubview(viewC)
    viewC.center = CGPointMake(viewC.bounds.size.width*0.1, -viewC.bounds.size.height*0.5)


}

我找到了解决方案。它的变化很小。在 viewForAnnotation 中隐藏基本标注如下,

anView!.canShowCallout = false