T
T
tiger_132020-06-16 13:18:21
Swift
tiger_13, 2020-06-16 13:18:21

Custom image flies in MKAnnotationView, how to fix it?

Hello!
placed on MKMapView MKAnnotation (preliminarily issued in the customAnnotation class for loading an array of data from a file). Next in func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? put a picture:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        guard annotation is customAnnotation else { return nil }
        
        let identifier = "Annotation"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
        
        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView!.canShowCallout = true
        } else {
            annotationView!.annotation = annotation
        }
        
        annotationView?.image = UIImage(named: "chicken")
        return annotationView
    }

Everything works well:
5ee89b8f35a8e922529990.jpeg

As soon as I exit the application (do not delete it from memory), and go back in, the cast image disappears:
5ee89bb32bd15037549521.jpeg

in this case, the function func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? is not called (that is, the problem is not in it).

Console - IconRenderer: HorizontalStretchPadding (18.000000, 18.000000) is larger than the image size (34.000000, 54.000000). Image will now use the center column of pixels to stretch.
But I do not think that this is a problem, since then the picture would not have been displayed initially.

Please tell me how to fix. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question