Mah*_*dra 10 iphone objective-c mkmapview ios ios10
我在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;
}
Run Code Online (Sandbox Code Playgroud)
小智 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 委托调用时,我也重绘 MKPolyline
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered
需要更多测试,但看起来有效
| 归档时间: |
|
| 查看次数: |
533 次 |
| 最近记录: |