use*_*410 8 objective-c mapkit mkmapview ios mkoverlay
在调整NSSlider时,如何在UIMapView上平滑调整MKCircleView的大小?苹果已经成功地做到这一点在查找好友创建地理围栏时,应用程序(http://reviewznow.com/wp-content/uploads/2013/03/find-my-friends-location-alerts-01.jpg),所以我想这在某种程度上是可能的.到目前为止,我已经尝试了以下解决方案,但结果非常"闪烁":
第一次尝试
我添加了一个具有更新半径的新MKCircleView,并在移除滑块更改值后立即移除(如此处建议MKOverlay不能平滑地调整大小).我也尝试过另一种方法:首先删除叠加层,然后添加一个新叠加层,但使用相同的"flickery"结果.
- (void)sliderChanged:(UISlider*)sender
{
double radius = (sender.value * 100);
[self addCircleWithRadius:radius];
[mapView removeOverlays:[self.mapView.overlays firstObject]];
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试
在链接的SO答案中,他建议NSOperation可用于"帮助您更快地创建MKCircle对象",从而在幻灯片更改值时使用上述添加/删除叠加层的方法使调整大小更加平滑.我做了一个实现,每当滑块改变时我就开始一个新的线程.在每个线程中,我删除所有旧的叠加层并添加一个新的叠加层.也许他还有其他一些实现方式,因为我这样做的方式在更改滑块时仍然会出现相同的闪烁.
- (void)sliderChanged:(UISlider*)sender
{
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(updateOverlayWithScale:)
object:[NSNumber numberWithFloat:sender.scale]];
[self.queue addOperation:operation];
}
Run Code Online (Sandbox Code Playgroud)
每个线程运行的方法:
- (void)updateOverlayWithScale:(NSNumber *)scale
{
MKCircle *circle = [MKCircle circleWithCenterCoordinate:self.currentMapPin.coordinate
radius:100*[scale floatValue]];
[self.mapView performSelectorOnMainThread:@selector(removeOverlays:) withObject:self.mapView.overlays waitUntilDone:NO];
[self.mapView performSelectorOnMainThread:@selector(addOverlay:) withObject:circle waitUntilDone:NO];
}
Run Code Online (Sandbox Code Playgroud)
第三次尝试
我还尝试实现我自己的MKOverlayView子类,它根据scale属性绘制自己.每当滑块改变时,我调用setNeedsDisplay并让它自己重绘,但我得到相同的闪烁.
- (void)sliderChanged:(UISlider*)sender
{
self.currentOverlayView.scale = sender.scale
[self.currentOverlayView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
而在我的自定义重叠视图我实现drawMapRect:zoomScale:inContext的:(CGContextRef)背景下这样的
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)context
{
double radius = [(MKCircle *)[self overlay] radius];
radius *= self.scale;
// ... Create a rect using the updated radius and draw a circle inside it using CGContextAddEllipseInRect ...
}
Run Code Online (Sandbox Code Playgroud)
那么,你有什么想法吗?提前致谢!
几个月前,我偶然发现了这个动画 MKCircleView。它还在 git 上有一个演示。所以我想你应该尝试一下!检查一下,因为您可能可以根据您的需要进行调整slider等。
感谢 yickhong 提供此内容YHAnimatedCircleView
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |