Аннотация смывает в MapKit - PullRequest
       28

Аннотация смывает в MapKit

0 голосов
/ 24 февраля 2020

Я работаю над MapKit в Swift и у меня возникли некоторые проблемы с ним. Я показываю аннотации с изображением на MapKit, и оно показывает одно изображение за 100 мс, а затем показывает реальное изображение.

extension MapVC: MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        var annView = mapView.dequeueReusableAnnotationView(withIdentifier: "pin")
        if annView == nil {
            annView = MKAnnotationView(annotation: annotation, reuseIdentifier: "pin")
            annView?.canShowCallout = true
        }

        let manager = SDWebImageManager.shared
        let imagePath = (annotation as! PointAnnotation).user?.photo
        manager.loadImage(with: URL(string: imagePath!), options: .continueInBackground, progress: nil) { (image, data, error, cacheType, finished, url) in
            if image != nil {
                annView?.image = image?.resizeImageWith(newSize: CGSize(width: 16, height: 16))?.circleMasked
            }
        }
        return annView
    }

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        let annotation = view.annotation
        let user = (annotation as! PointAnnotation).user
        let me = mainStore.state.profile
        if user === me {
            return
        }
        let vc = ChatVC.storyBoardInstance
        vc.user = user
        self.navigationController?.pushViewController(vc, animated: true)
    }
}

, пожалуйста, помогите мне в этой проблеме

1 Ответ

0 голосов
/ 25 февраля 2020

Попробуйте следующий код перед loadImage.

annView?.image = nil

manager.loadImage(with:....

EDITED

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    var annView = mapView.dequeueReusableAnnotationView(withIdentifier: "pin")
    if annView == nil {
        annView = MKAnnotationView(annotation: annotation, reuseIdentifier: "pin")
        annView?.canShowCallout = true

        let manager = SDWebImageManager.shared
        let imagePath = (annotation as! PointAnnotation).user?.photo
        manager.loadImage(with: URL(string: imagePath!), options: .continueInBackground, progress: nil) { (image, data, error, cacheType, finished, url) in
            if image != nil {
                annView?.image = image?.resizeImageWith(newSize: CGSize(width: 16, height: 16))?.circleMasked
            }
        }
    } else {
        annView?.annotation = annotation
    }
    return annView
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...