代码之家  ›  专栏  ›  技术社区  ›  J.Doe

不能选择MKViewAnnotation两次?

  •  7
  • J.Doe  · 技术社区  · 7 年前

    我把别针放在地图上,当我点击它们时,我会呼叫 didSelect

    对我来说,这听起来像是正在选择pin,并且 DID选择

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        view.isSelected = false
    }
    

    如何允许我的注释连续被点击多次?

    2 回复  |  直到 6 年前
        1
  •  11
  •   Reinier Melian    7 年前

    尝试使用此方法 deselectAnnotation

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
         //do what you need here
         mapView.deselectAnnotation(view.annotation, animated: true)
    }
    

    希望这有帮助

        2
  •  2
  •   Raz    7 年前

    这将允许显示 callout

    internal func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    
        view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(mapPinTapGestureRecognizer)))
    }
    
    @objc private func mapPinTapGestureRecognizer(gestureRecognizer: UITapGestureRecognizer) {
    
        // Will get called on the second time the pin is selected.
        // And then, after that, it will be called every time.
    }
    

    当注释不再被选中时,不要忘记删除识别器。

    internal func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
    
        // Remove the gesture recognizer when the annotation is no longer selected.
    }