I have subclassed MKAnnotationView to create an annotation that basically draws a circle around a point on the map using override drawRect. The circle is perfectly drawn in the following situations (in the simulator):
- When loading a map view
- When scrolling, but only when the swipe movement is stopped before touching (so that the card does not “take” after touching)
- In zoom mode, press
The circle will disappear when one of the following occurs:
- Swipe the screen where the “coast” map ends after touching.
- 2x scaling
The circle will appear again if any of the actions in the "working" group is taken after its disappearance.
What could be the reason for this? I'm not an expert on drawing / rendering / layout (to be honest, I'm not a C or iPhone expert either).
Here is some slightly simplified code that works best for my subclass of MKAnnotationView:
- (void)drawRect:(CGRect)rect {
[self drawCircleAtPoint:CGPointMake(0,0) withRadius:self.radiusInPixels andColor:self.circleAnnotation.color];
}
- (void)drawCircleAtPoint:(CGPoint)p withRadius:(int)r {
CGContextRef contextRef = UIGraphicsGetCurrentContext();
float alpha = 0.75;
CGContextSetRGBFillColor(contextRef, 255, 0, 0, alpha);
CGContextSetRGBStrokeColor(contextRef, 255, 0, 0, alpha);
CGContextStrokeEllipseInRect(contextRef, CGRectMake(0, 0, 2*r, 2*r));
}
source
share