2010-02-17 48 views
5

我有子类MKAnnotationView创建基本借鉴了通过drawRect中的覆盖地图视图点周围一圈的注释。圆在以下情况下绘制细(在模拟器):MKAnnotationView消失上刷卡并双击缩放

  • 在地图视图
  • 在滑动的初始负荷,但只有当滑动运动之前触摸端部,使得地图不停止( “海岸”触摸结束后)
  • 在双指缩放

时有下列行为的发生,该圆圈将消失:

  • 刷卡其中图“海岸”触摸结束后
  • 双击缩放如果有的话,在“工作”组的行动已经消失后,采取

的圆圈会重新出现。

什么可能导致这种情况?我不是一个绘图/显示/布局专家(坦率地说,我不是一个obj C或iPhone专家)。

下面是一些稍微简化代码,似乎最相关的从我的MKAnnotationView子类:

- (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)); 
} 
+0

也看到这种行为,寻找解决的办法可以找到... – 2010-02-25 08:36:32

+0

甚至我面临同样的问题,有没有运气? – Ameya 2010-08-29 12:24:39

+0

是在“非”工作组中调用的drawRect? – Magnus 2011-01-13 08:29:44

回答

2

你加这个方法?

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

这是从苹果的所谓WeatherMap代码示例应用程序,它是由苹果公司开发者中心删除拍摄,但可以在github上 https://github.com/acekiller/iOS-Samples/blob/master/WeatherMap/Classes/WeatherAnnotationView.m

+0

示例代码中的天气注释消失并在每次拖动/缩放后重新出现。 – Robert 2011-06-09 14:24:47

+1

这是因为它们以这种方式实现,请参阅' - (void)mapView:(MKMapView *)map regionDidChangeAnimated:(BOOL)'MapViewController.m'中的方法' – 2011-06-13 13:29:20

+0

为我工作。 Dunja,谢谢你! – pho0 2012-09-12 22:42:43