mapkit - отображение пользовательских изображений - PullRequest
0 голосов
/ 12 февраля 2020

Ниже мой код, отображающий аннотации, у меня есть вопрос, почему пользовательские изображения отображаются только при второй загрузке представления?

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        guard annotation is MKPointAnnotation else { return nil }

        let identifier = "Annotation"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)


        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView!.isEnabled = true
            annotationView!.canShowCallout = true
            print("1")
        } else {
            annotationView!.annotation = annotation
            print("2")
        }

        let detailAnnotation = annotation as! WaypointsAnnotation
          if (detailAnnotation.type == "Current") {

              annotationView!.image = UIImage(named: "point5")
              //let transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
              //annotationView!.transform = transform

          }
          if (detailAnnotation.type == "Waypoint") {

              annotationView!.image = UIImage(named: "point6")
              //let transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
              //annotationView!.transform = transform

          }

Спасибо за ответ.

1 Ответ

1 голос
/ 12 февраля 2020

Попробуйте изменить тип аннотации с MKPinAnnotationView на MKAnnotationView.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...