我正在使用 Objective C 为 iOS 9.0 及更高版本开发应用程序。
该应用程序包含一个带有 MKMapView 对象的视图控制器。视图控制器是地图视图委托。
我在 viewWillAppear:animated 的实现中添加 MKCircle 覆盖时遇到问题。
使用该addOverlay:level:
方法并不能解决问题。
实现看起来像:
- (void)viewDidLoad {
[super viewDidLoad];
[self.mapView setDelegate:self];
[self.mapView setZoomEnabled:YES];
[self.mapView setScrollEnabled:YES];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.locationCircle = [MKCircle circleWithCenterCoordinate:self.locationPin.coordinate radius:1000000.0];
[self.mapView addOverlay:self.locationCircle];
}
- (MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKCircle class]]) {
MKCircleRenderer *renderer = [[MKCircleRenderer alloc] initWithCircle:(MKCircle *)overlay];
renderer.fillColor = [[UIColor yellowColor] colorWithAlphaComponent:0.25];
return renderer;
} else {
return [self.superclass rendererForOverlay:overlay];
}
}
具体来说,一旦地图视图试图显示圆圈覆盖的任何部分,应用程序就会崩溃。
该应用程序成功地在地图视图上渲染多边形叠加层和各种引脚注释。错误消息详细信息是:
2016-11-07 12:35:21.643 [MKCircle pointCount]: unrecognized selector sent to instance 0x6000004902c0
2016-11-07 12:35:21.645 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKCircle pointCount]: unrecognized selector sent to instance 0x6000004902c0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010cdc334b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010c82421e objc_exception_throw + 48
2 CoreFoundation 0x000000010ce32f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010cd48c15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010cd48798 _CF_forwarding_prep_0 + 120
5 MapKit 0x0000000109af40a3 CreatePathForPolygon.38297 + 57
6 MapKit 0x0000000109af3e4c -[MKPolygonRenderer createPath] + 128
7 MapKit 0x0000000109aeefda -[MKOverlayPathRenderer drawMapRect:zoomScale:inContext:] + 72
8 MapKit 0x0000000109aefd89 __47-[MKOverlayRenderer overlay:drawKey:inContext:]_block_invoke + 671
9 MapKit 0x0000000109aefdda _worldsForBounds.37697 + 58
10 MapKit 0x0000000109aef99f -[MKOverlayRenderer overlay:drawKey:inContext:] + 224
11 VectorKit 0x00000001170e0534 __40-[VKRasterOverlayTileSource _queueDraw:]_block_invoke + 484
12 libdispatch.dylib 0x000000010de3a980 _dispatch_call_block_and_release + 12
13 libdispatch.dylib 0x000000010de640cd _dispatch_client_callout + 8
14 libdispatch.dylib 0x000000010de43499 _dispatch_queue_override_invoke + 1733
15 libdispatch.dylib 0x000000010de453b7 _dispatch_root_queue_drain + 720
16 libdispatch.dylib 0x000000010de4508b _dispatch_worker_thread3 + 123
17 libsystem_pthread.dylib 0x000000010e20d4de _pthread_wqthread + 1129
18 libsystem_pthread.dylib 0x000000010e20b341 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
实验中,我发现如果圆圈覆盖在地图的一部分未显示在屏幕上,则可以添加圆圈覆盖而不会使应用程序崩溃。一旦用户平移到圆圈所在的地图部分,就会发生这种崩溃。
将模拟器与 iOS 10.1 和 iOS 9.0 一起使用时会出现该错误。
任何关于为什么会发生这种情况的想法将不胜感激。