
我在MKMapView上绘制MKPolyLine。在iOS 10之前,is运行得很好。在iOS 10中,它显示的是色块而不是路由。
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
[![enter image description here][1]][1]if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolyline *route = overlay;
@try {
MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
routeRenderer.strokeColor = [UIColor colorWithRed:20/255.0 green:153/255.0 blue:255/255.0 alpha:1.0];
routeRenderer.lineWidth = 3;
[routeRenderer setNeedsDisplay];
return routeRenderer;
}
@catch (NSException *exception) {
NSLog(@"exception :%@",exception.debugDescription);
}
}
else return nil;
}发布于 2016-09-30 17:26:44
它看起来像是iOS 10的bug,我花了很多时间来“破解”这个bug。
当我重新绘制MKPolyline(删除旧的并添加新的)时,我发现只有一个解决方案,它应该是在dispatch_after中调用它,它看起来应该在地图创建形状时重新绘制。(imho)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // Add MKPolyline to mapView });
当mapView委托调用时,我也会重新绘制MKPolyline
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered
它需要更多的测试,但看起来是有效的。
发布于 2016-11-04 06:36:51
我遇到了同样的问题,解决了我的问题的是,添加覆盖的代码是从viewDidLoad调用的。一旦我把代码移到viewDidAppear,问题就解决了。
https://stackoverflow.com/questions/39784560
复制相似问题