2010-02-17 50 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