2016-09-30 55 views
10

enter image description hereMKmapView覆蓋圖顯示顏色補丁iOS 10

我正在通過MKMapView繪製MKPolyLine。在iOS 10之前工作正常。在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; 
} 

回答

1

它看起來像iOS 10的bug,我花了很多時間來「破解」這個bug。

我發現只有一個解決方案,當我重繪MKPolyline(刪除舊的並添加新的)它應該在dispatch_after中調用它,它看起來應該在地圖變形時重繪。 (恕我直言)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // Add MKPolyline to mapView });

當MapView的委託調用

​​

它需要更多的測試,但它看起來它的工作原理

+0

好的好友,謝謝你的回覆。我會檢查並讓你知道 – Mahendra

0

我遇到了同樣的問題,我也重繪MKPolyline什麼解決我的問題是添加覆蓋的代碼是從viewDidLoad調用的。一旦我將代碼移到viewDidAppear中,問題就解決了。

+0

以及...這還不夠。 – dardi

+1

我必須擴展MKPolylineRenderer並覆蓋 - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale總是返回YES。 – dardi

+0

你解決了將布爾值設置爲YES的問題嗎? – GGirotto