2017-12-30 5 views
0

지도가있는보기가 있습니다. 다음을 달성하고 싶습니다.지도에서 사용자가지도를 탭하여지도의 다른 지점을 탭할 때까지 주석이 표시되고 선택됩니다 (이 경우 설명 풍선이 표시됨).이 경우 이전 주석을 제거해야합니다).주석의 선택 취소를 방지하는 방법 자동으로 신속하게

문제는 내가지도를 탭하면 약간의 시간 동안 주석이 추가되고 선택되며 어떻게 든 선택 해제됩니다 (콜 아웃이 사라짐). 내가 다른 지점에서 사용자가 탭 할 때까지 설명 풍선이 계속 나타나기를 바란다.

다음은 내 시도이다. 아무도 도와 줄 수 없습니까?

@objc func handleTap(_ sender: UITapGestureRecognizer){ 

    //...some code that computes the country code starting from latitude and longitude 

      var countryCurrency = "" 

      func countryRequest(countryLabel: String, completion: @escaping (String)->()){ 
       //api request that receives the currency name of the country 
       completion(countryCurrency) 
      } 
      countryRequest(countryLabel: countryLabel){ countryCurrency in 

       DispatchQueue.main.async { 

        let locat:CLLocationCoordinate2D = CLLocationCoordinate2DMake(locationCoord.latitude, locationCoord.longitude) 
        let annotation = MKPointAnnotation() 
        annotation.coordinate = locat 
        annotation.title = countryCurrency 
        annotation.subtitle = "subtitle" 
        self.mapView.addAnnotation(annotation) 
        self.mapView.selectAnnotation(annotation, animated: true) 

       } 

      } 
} 

는 또한 콜 아웃을 사용자 정의 할 MKMapViewDelegate의 확장이 있습니다

extension MapsItem: MKMapViewDelegate { 

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

    if !(annotation is MKPointAnnotation){ 
     return nil 
    } 

    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "demo") 
    if annotationView == nil { 
     annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "demo") 
     annotationView!.canShowCallout = true 
     annotationView!.sizeToFit() 
    } 
    else{ 
     annotationView!.annotation = annotation 
    } 

    return annotationView 

} 
} 

사전에 감사!

답변

1

func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) 
    { 

     if(!isTappingNow) 
     { 

      self.mapView.selectAnnotation(view.annotation, animated: false) 
     } 

    } 
+1

매우 감사 선택한 후 주석을 추가하기 전에 false로 사실이

세트 isTappingNow을보십시오! – Frank

관련 문제