我已經將MKCircle作爲MKOverlay添加到了我的MKMapView中。我還加了一個UISlider來決定圓的半徑。不幸的是,當使用它時,它看起來有點「滯後」,不像我想要的那樣平滑。MKOverlay不能順利調整大小
例子: http://dl.dropbox.com/u/3077127/mkoverlayDelay.mov
這是我的代碼:
- (void)addCircle
{
// draw the radius circle for the marker
double radius = 2000.0;
MKCircle *circle = [MKCircle circleWithCenterCoordinate:location radius:radius];
[circle setTitle:@"background"];
[mapView addOverlay:circle];
MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:location radius:radius];
[circleLine setTitle:@"line"];
[mapView addOverlay:circleLine];
}
- (void)addCircleWithRadius:(double)radius
{
MKCircle *circle = [MKCircle circleWithCenterCoordinate:location radius:radius];
[circle setTitle:@"background"];
[mapView addOverlay:circle];
MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:location radius:radius];
[circleLine setTitle:@"line"];
[mapView addOverlay:circleLine];
}
- (void)sliderChanged:(UISlider*)sender
{
[mapView removeOverlays:[mapView overlays]];
double radius = (sender.value * 100);
[self addCircleWithRadius:radius];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
MKCircle *circle = overlay;
MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease];
if ([circle.title isEqualToString:@"background"])
{
circleView.fillColor = UIColorFromRGB(0x598DD3);
circleView.alpha = 0.25;
}
else
{
circleView.strokeColor = UIColorFromRGB(0x5C8AC7);
circleView.lineWidth = 2.0;
}
return circleView;
}
有誰知道我如何能撫平這有什麼建議?
最好的問候,
保羅Peelen
對於很好地記錄的問題+1。有沒有必要刪除覆蓋,爲什麼不更新它? – 2011-02-02 15:51:30
謝謝!我不認爲有任何需要..但我怎樣才能更新覆蓋? – 2011-02-02 16:12:44
我不確定你可以嗎?我一直認爲MapKit疊加層是不可變的,一旦創建就不能修改它們。這個答案建議相同:http://stackoverflow.com/questions/3171572/how-to-update-mkpolyline-mkpolylineview – lxt 2011-02-05 17:18:08