15-year update...
Syntax update to the excellent @Anurag answer
Number of your annotations which are currently visible:
let k = mapView.annotations(in: mapView.visibleMapRect).count
Check if a particular annotation is still on screen:
let momAnnotation = mapView.annotations[12]
let momVisible = mapView
.annotations(in: mapView.visibleMapRect)
.contains(momPosition)
A very common pattern:
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
if mapView.annotations(in: mapView.visibleMapRect).count <
mapView.annotations.count {
.. show your "reset view" button
}
else {
.. hide your "reset view" button
}
}
///Widen the map to include all annotations, "default view"
@IBAction func tapResetViewButton() {
mapView.showAnnotations(mapView.annotations, animated: true)
}
MKMapRect vs. CGRect:
Just as @Anurag says, take care for the difference between MKMapRect and plain-old bounds/frames, they are quite different.
PERFORMANCE ISSUE:
Note that mapView.annotations(in: ..).count
is INCREDIBLY faster than counting them yourself. As a general rule, never iterate through mapView.annotations, because, there's likely a built-in function which does what you need incredibly faster.