代码之家  ›  专栏  ›  技术社区  ›  user1904273

在swift中显示mkannotationview的disclosureindicator的标注

  •  0
  • user1904273  · 技术社区  · 6 年前

    我可以使用以下代码在我的地图注释中显示一个公开图标。

      annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
                annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
    

    当您按下披露图标时,它会闪烁,但不会发生其他事情。我试着在它上面放一个按钮处理程序,但它不是一个按钮,所以编译器拒绝了。我需要创建一个完整的GestureRecognizer来让它做任何事情吗?或者我要如何按下指示器来显示关于位置的信息?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Shehata Gamal    6 年前

    你需要这个委托方法

    func mapView(_ mapView: MKMapView, 
       annotationView view: MKAnnotationView, 
       calloutAccessoryControlTapped control: UIControl)
    

    具有

    self.mapView.delegate = self
    
        2
  •  -1
  •   Satish    6 年前

    试试这个

       let btn = UIButton(type: .detailDisclosure)
       btn.addTarget(self, action: #selector(btnDisclosureAction(_:)), for: .touchUpInside)
       annotationView.rightCalloutAccessoryView = btn
    
        @objc func btnDisclosureAction(_ sender: UIButton) {
            // you action
        }