开发者

MKAnnotationView disappearing on swipe and double-tap zoom

开发者 https://www.devze.com 2022-12-20 04:48 出处:网络
I have subclassed MKAnnotationView to create an annotation that basically draws a circle around a point on a map view through override of drawRect.The circle draws 开发者_Go百科fine in the following s

I have subclassed MKAnnotationView to create an annotation that basically draws a circle around a point on a map view through override of drawRect. The circle draws 开发者_Go百科fine in the following situations (in the simulator):

  • On initial load of the map view
  • On swipe, but only when swipe motion is stopped before touch ends (so that map doesn't "coast" after touch ends)
  • On pinch zoom

The circle will disappear when any of the following actions occur:

  • Swipe where map "coasts" after touch ends
  • Double-tap zoom

The circle will reappear if any of the actions in the "working" group are taken after it has disappeared.

What might cause this? I'm not a draw/display/layout expert (frankly, I'm not an obj C or iPhone expert either).

Here is some slightly simplified code that seems most relevant from my MKAnnotationView subclass:

- (void)drawRect:(CGRect)rect {
    // Drawing code
 [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);

    // Draw a circle (border only)
    CGContextStrokeEllipseInRect(contextRef, CGRectMake(0, 0, 2*r, 2*r));
}


Did you add this method?

- (void)setAnnotation:(id <MKAnnotation>)annotation
{
    [super setAnnotation:annotation];
    [self setNeedsDisplay];
}

This is taken from Apple's sample code app called WeatherMap which was removed from Apple Developer Center, but can be found on github https://github.com/acekiller/iOS-Samples/blob/master/WeatherMap/Classes/WeatherAnnotationView.m

0

精彩评论

暂无评论...
验证码 换一张
取 消