iOS7では、rectForMapRect:
とmapRectForRect:
は廃止され、現在はMKOverlayRenderer
クラスの一部です。むしろMapView
mapRectThatFits: edgePadding:
メソッドを使用することをお勧めしたいと思います。 2017年
MKMapRect visibleRect = self.mapView.visibleMapRect;
UIEdgeInsets insets = UIEdgeInsetsMake(50, 50, 50, 50);
MKMapRect biggerRect = [self.mapView mapRectThatFits:visibleRect edgePadding:insets];
最新スウィフト
func updateMap() {
mkMap.removeAnnotations(mkMap.annotations)
mkMap.addAnnotations(yourAnnotationsArray)
var union = MKMapRectNull
for p in yourAnnotationsArray {
// make a small, say, 50meter square for each
let pReg = MKCoordinateRegionMakeWithDistance(pa.coordinate, 50, 50)
// convert it to a MKMapRect
let r = mkMapRect(forMKCoordinateRegion: pReg)
// union all of those
union = MKMapRectUnion(union, r)
// probably want to turn on the "sign" for each
mkMap.selectAnnotation(pa, animated: false)
}
// expand the union, using the new #edgePadding call. T,L,B,R
let f = mkMap.mapRectThatFits(union, edgePadding: UIEdgeInsetsMake(70, 0, 10, 35))
// NOTE you want the TOP padding much bigger than the BOTTOM padding
// because the pins/signs are actually very tall
mkMap.setVisibleMapRect(f, animated: false)
}
このヘルプ? :http://stackoverflow.com/questions/8465149/mkmaprect-zooms-too-much – Firo
メモ、2017年のためにAppleは今**すべての仕事を終えました**、以下の回答を参照してください – Fattie