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
}
}
感謝を!
はどうもありがとうございまし選択した後、注釈を追加する前に、偽の真にこの
セットisTappingNowをお試しください! – Frank