MKOverlay not resizing smoothly(MKOverlay 无法顺利调整大小)
问题描述
我已将 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?
最好的问候,
保罗·皮伦
Best regards,
Paul Peelen
推荐答案
我已经尝试过你的代码,并找到了一个非常简单的方法来使它更流畅.
I have tried your code and found a very easy way to make it smoother.
如果更改调用顺序:- (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 无法顺利调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MKOverlay 无法顺利调整大小


基础教程推荐
- LocationClient 与 LocationManager 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01