MKMapView覆盖层绘制显示颜色块iOS 10

10

我正在MKMapView上绘制MKPolyLine。在iOS 10之前,它一直正常工作。在iOS 10中,除了路线之外,它还显示颜色补丁。

enter image description here

 - (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;
}
2个回答

1

看起来像是iOS 10的一个bug,我花了很多时间来“破解”这个bug。

我只找到了一种解决方法,当我重新绘制MKPolyline(删除旧的并添加新的)时,应该在dispatch_after中调用它,看起来应该在地图形状变化时重新绘制。(我个人认为)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // 将MKPolyline添加到mapView中 });

当mapView的delegate被调用时,我也重新绘制MKPolyline

- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered

需要进行更多测试,但看起来它可以工作


好的伙计,谢谢你的回复。我会检查并告诉你。 - Mahendra

0
我遇到了同样的问题,解决方法是将添加覆盖层的代码从viewDidLoad中调用。一旦我将代码移动到viewDidAppear中,问题就得到了解决。

好吧...这还不够。 - dardi
1
我不得不扩展MKPolylineRenderer并覆盖-(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale,以始终返回YES。 - dardi
你解决了将布尔值设置为YES的问题了吗? - GGirotto

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接