自定义 MKAnnotationView 想要再次被点击

Custom MKAnnotationView want to be tapped again

我的自定义 MKAnnotationView 有问题。 我从我的 REST api 下载坐标并将其放置在地图上,并使用以下代码将图钉放置在地图上:

private func refreshMapView(andCenterMap: Bool){
    DispatchQueue.main.async { [weak self] in
        guard let self = self else {
            return
        }

        self.mapView.addAnnotations(self.spotsArray)
        if andCenterMap {
            self.centerMap(at: self.mapView.userLocation.coordinate)
        }
    }
}

大头针放的我自动缩放地图

这里是创建自定义注释的代码:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    // Do not touch the annotation of the user location
    if annotation.isKind(of: MKUserLocation.self){
        return nil
    }

    let annoIdentifier = "SPOT"
    var annotationView: MKAnnotationView?

    if let dequeued = mapView.dequeueReusableAnnotationView(withIdentifier: annoIdentifier) {
        annotationView = dequeued
    }else{
        let av = MKAnnotationView(annotation: annotation, reuseIdentifier: annoIdentifier)
        annotationView = av
    }

    // Changing the image of the pin
    annotationView!.annotation = annotation
    if let image = UIImage(named: "map_pin") {
        annotationView!.image = image
        let deltaY = image.size.height/2
        annotationView!.centerOffset = CGPoint(x: 0.0, y: -deltaY)
    }else{
        annotationView!.image = nil
    }

    return annotationView
}

如您所见,我的自定义图钉使用的是这张图片(@1x、@2x、@3x)

点击的人 我想显示 "detail view" 并且我使用注释作为发件人以便在下一个视图中获得我需要的所有信息。 这里的代码:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        guard let ann = view.annotation else {
            return
        }
        if ann.isKind(of: MKUserLocation.self){
            return
        }
        self.performSegue(withIdentifier: "showDetailSegue", sender: ann)
}

所以我提供了我需要的所有数据,然后我可以返回 "map view"。

问题是:

在地图视图中,如果我想再次 select 相同的注释,则无法再点击。

我可以看到它(在正确的位置),但我可以 select 只有当我放大一点并点击 "around" 注释时才能再次看到它。

有什么解决这个问题的建议吗?

提前致谢!

添加 didSelect

的这一端
mapView.deselectAnnotation(ann,animated:false)