MKOverlay没有顺利调整大小 [英] MKOverlay not resizing smoothly
问题描述
我已将MKCircle作为MKOverlay添加到我的MKMapView中。我还添加了一个UISlider来决定圆的半径。不幸的是,当使用它时,它似乎有点滞后,不像我想要的那样流畅。
I have added a MKCircle as MKOverlay to my MKMapView. Also I added an UISlider to decide the radius of the circle. Unfortunately when using this it seems a bit "laggy", not smootly like I want it to be.
示例:
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;
}
有没有人对我如何平滑这个有任何建议?
Does anybody have any suggestions on how I can smoothen this?
最好的问候,
Paul Peelen
Best regards,
Paul Peelen
推荐答案
我已经尝试过你的代码并找到一种非常简单的方法让它更顺畅。
I have tried your code and found a very easy way to make it smoother.
如果你改变了调用的顺序: - (void) sliderChanged :( UISlider *)发件人
If you change the order of the calls in: - (void)sliderChanged:(UISlider*)sender
你可以调用 [self addCircleWithRadius:radius];
在调用 [mapView removeOverlays:[mapView overlays]];
请确保您不要删除刚添加的叠加层,只删除旧的叠加层。
Just make sure you dont remove the overlays you just added, only the old ones.
这样可以让您更加顺畅地调整大小,特别是在新圈子小于旧圈子。
This will give you a smoother resizing, specially when the new circle is smaller than the old one.
对于较大的圈子,你可能最好使用 NSOperations
来确保更快地创建视图,这将使其更加平滑。
For circles that are bigger you are probably better off using NSOperations
to ensure the views are created faster, this will make it smoother.
希望这会有所帮助。
这篇关于MKOverlay没有顺利调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!