我使用了以下代码,这些代码发布在整个 SO 以及网络上。它在 4 英寸屏幕上工作正常,但由于某种原因,5 英寸屏幕没有提供所需的输出。
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in _mapView.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}
zoomRect = MKMapRectMake(zoomRect.origin.x - 40 * (zoomRect.size.width / _mapView.frame.size.width),
zoomRect.origin.y - 60 * (zoomRect.size.height / _mapView.frame.size.height),
zoomRect.size.width + 80 * (zoomRect.size.width / _mapView.frame.size.width),
zoomRect.size.height + 80 * (zoomRect.size.height / _mapView.frame.size.height));
[_mapView setVisibleMapRect:zoomRect
animated:NO];