Using Marco's answer, I came to this solution.
Every time a region changes, I change the ViewController's isAtBigZoom .
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) { isAtBigZoom = mapView.region.span.latitudeDelta < 0.01 }
Then in the didSet property, I execute this code.
var isAtBigZoom = false { didSet { // this guard ensures, that the showing and hiding happens only once guard oldValue != isAtBigZoom else { return } // in my case I wanted to show/hide only a certain type of annotations for case let annot as MapTextAnnotation in mapView.annotations { mapView.viewForAnnotation(annot)?.alpha = isAtBigZoom ? 1 : 0 } } }
If you also want to start with hidden annotations, just add the alpha change code to the viewForAnnotation method.
Works great, and I didn't notice any big performance issues. Although this may change with an increase in the number of annotations ...
source share