Make MKMapView only zoom in on the centerCoordinat

2019-03-05 17:03发布

I have a MKPinAnnotationView that is always in the center of the map. When panning and zooming the pin gives me the center coordinates (lat/long) of the map.

Currently when you zoom in, it just zooms into wherever your directing the map to zoom into.

I'd really like to lock the zoom onto the pin.

Any ideas on how I'd achieve this?

1条回答
小情绪 Triste *
2楼-- · 2019-03-05 17:42

Assuming by MKPinAnnotation you mean MKPinAnnotationView, you can access the annotation's coordinate and use that to create a region and subsequently set the region of the mapView to that region centered on the coordinate:

MKCoordinateRegion region = MKCoordinateRegionMake(pin.annotation.coordinate, MKCoordinateSpanMake(.05, .05));
[self.mapView setRegion:region animated:YES];
查看更多
登录 后发表回答