【问题标题】:MapKit annotation how to add detail disclosure info button?MapKit注释如何添加详细信息披露信息按钮?
【发布时间】:2016-09-27 19:41:15
【问题描述】:

我将annotation放在地图上,点击图钉后,右侧应该有一个detail disclosure info button,所以我可以在点击按钮后添加更多代码。但是当我运行该项目时,单击图钉,没有出现info button。谁能提供代码添加disclosure info button?

我期待右侧的信息按钮:

我的代码:

extension ViewController: MKMapView{


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



  }

【问题讨论】:

    标签: ios swift xcode mapkitannotation


    【解决方案1】:

    创建一个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
            }
        }
    

    【讨论】:

    • @Rob,你的意思是这样的if annotation.isMember(of:MKUserLocation.self){ return nil }?
    • @Rob,更新了示例。再次感谢您的反馈!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多