For an app, I have to place a MKCircle annotation on a MKMapView. However, the circle needs to be moved/resized. I know this has been asked, e.g. Moving MKCircle in MKMapView where removing/adding the annotation is suggested to get that behavior.
However, I consider the drawing being very slow, like the user in this post: Smooth resizing of MKCircle. Since there are now answers to this question, the question seemed to use YHAnimatedCircleView
. By slow I mean, when I use a UISlider to change the radius of the circle, the redrawing is sloppy and I can also notice the tiles being used to draw it.
I created a small test code, overriding drawMapRect
of a subclasses MKOverlayRenderer. The code is as follows:
-(void) drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)context
{
MKCircle* circleOverlay = (MKCircle*)self.overlay;
CLLocationCoordinate2D point = circleOverlay.coordinate;
CGPoint locationPoint =
[self pointForMapPoint:MKMapPointForCoordinate(point)];
CGFloat radius =
MKMapPointsPerMeterAtLatitude(circleOverlay.coordinate.latitude) *
circleOverlay.radius;
CGRect circleRect = CGRectMake(locationPoint.x - radius,
locationPoint.y - radius,
radius * 2.0, radius * 2.0);
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextFillEllipseInRect(context, circleRect);
CGContextRestoreGState(context);
}
When I move the UISlider the old annotation is removed and the new MKCircle
with different radius is placed and the drawMapRect
method gets called.
However, even this small example shows sloppy drawing when resizing the circle.
Questions:
- Is the above example entirely correct or am I doing something wrong with drawing?
- If the example is correct, why is the redrawing of the circle when resizing it so slow/sloppy?