快速向 MKMapView 添加叠加层!这可能吗?
你好我有以下问题! 我确实向我的 MKMapView 添加了很多叠加层! 例如,我添加了 150 个叠加层,但由于某种原因,并非所有叠加层都显示出来! 我知道 mapView:viewForOverlay:
被调用了 150 次。 我发现,如果我将以下内容添加到: [NSThread sleepForTimeInterval:1]
到创建所有叠加层的方法中,所有叠加层都会显示出来。 那么叠加层的添加速度是否可以很快呢?或者可能是什么问题?
所有叠加层都是在后台线程中创建的,如下所示!
MKPolyline* routeLine;
....
....
dispatch_async(dispatch_get_main_queue(), ^{
[self.myMKMapView addOverlay:routeLine];
});
这是 mapView:viewForOverlay:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
MKPolylineView * rLV = [[[MKPolylineView alloc] initWithPolyline:overlay]autorelease];
rLV.fillColor = [UIColor blueColor];
rLV.strokeColor = [UIColor blueColor];
rLV.lineWidth = 1;
rLV.alpha = 0.5;
overlayView = rLV;
return overlayView;
}
Hi I have the following problem!
I do add a lot of Overlays to my MKMapView!
For example I add 150 Overlays, but for some reason not all of them show up!
I know that mapView:viewForOverlay:
gets called 150 times.
I found out that if I add this: [NSThread sleepForTimeInterval:1]
to the method where all my overlays are created all the overlays show up.
so can it be that the overlays being added to fast? or what could be the problem?
all the overlays are created in a background thread like this!
MKPolyline* routeLine;
....
....
dispatch_async(dispatch_get_main_queue(), ^{
[self.myMKMapView addOverlay:routeLine];
});
and this is the mapView:viewForOverlay:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
MKPolylineView * rLV = [[[MKPolylineView alloc] initWithPolyline:overlay]autorelease];
rLV.fillColor = [UIColor blueColor];
rLV.strokeColor = [UIColor blueColor];
rLV.lineWidth = 1;
rLV.alpha = 0.5;
overlayView = rLV;
return overlayView;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您多次调用
addOverlay:
(并在主线程上排队数百个块),则使用数组调用addOverlays:
方法可能会获得更好的结果。If you're calling
addOverlay:
multiple times (and queueing up hundreds of blocks on the main thread), you may get better results calling theaddOverlays:
method with an array instead.