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 无法顺利调整大小
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01