问题
Below is very simple custom overlay object:
@interface Overlay : NSObject <MKOverlay>
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) MKMapRect boundingMapRect;
@end
@implementation Overlay
- (id)init {
self = [super init];
if (self) {
_coordinate = CLLocationCoordinate2DMake(37.78577, -122.40645);
_boundingMapRect.origin = MKMapPointForCoordinate(_coordinate);
_boundingMapRect.size = MKMapSizeMake(200, 200);
}
return self;
}
@end
OverlayView is also very straightforward:
@implementation OverlayView
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
Overlay* overlay = (Overlay*)[self overlay];
CGRect r = [self rectForMapRect:overlay.boundingMapRect];
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextSetLineWidth(context, 10);
CGContextStrokeEllipseInRect(context, r);
}
@end
And its boundingMapRect
property updated on button click:
-(IBAction)onUpdateOverlayBtn:(id)sender
{
_overlay.boundingMapRect = MKMapRectInset(_overlay.boundingMapRect, -3000, -3000);
[_overlayView setNeedsDisplayInMapRect:_overlay.boundingMapRect];
}
The problem appears when MKMapView is zoomed in (right side):

Test Xcode project on bitbucket
来源:https://stackoverflow.com/questions/15525526/mkmapview-not-updating-overlay-correctly-after-changing-its-boundingmaprect