1

我正在放置地图,单击图钉后,右侧annotation应该有一个,因此我可以在点击按钮后添加更多代码。detail disclosure info button但是当我运行项目时,点击图钉,没有info button出现。任何人都可以提供要添加的代码disclosure info button吗?

我期待右侧的信息按钮:在此处输入图像描述

我的代码:

extension ViewController: MKMapView{


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



  }
4

1 回答 1

5

创建一个MKAnnotationView并向其添加一个按钮。所以:

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        if annotation is MKUserLocation { return nil }

        if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "") {
            annotationView.annotation = annotation
            return annotationView
        } else {
            let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:"")
            annotationView.isEnabled = true
            annotationView.canShowCallout = true

            let btn = UIButton(type: .detailDisclosure)
            annotationView.rightCalloutAccessoryView = btn
            return annotationView
        }
    }
于 2016-09-27T19:43:34.717 回答