虽然我尝试了上面列出的所有答案但我仍然遇到了崩溃,但我有一个部分解决方案。
但是,当我将缩放设置为 FALSE 时,崩溃完全停止了!?为什么?我想放大它看起来不错:
mapView.setVisibleMapRect(zoomRect, animated: false)
这是来自这个函数(我也在其中取消选择上面建议的集群注释):
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
lastTouchedAtCoordinate = view.annotation?.coordinate
guard let annotation = view.annotation else { return }
if let cluster = annotation as? MKClusterAnnotation {
var zoomRect = MKMapRectNull
for annotation in cluster.memberAnnotations {
self.mapView.deselectAnnotation(annotation, animated: false)
let annotationPoint = MKMapPointForCoordinate(annotation.coordinate)
let pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0)
if MKMapRectIsNull(zoomRect) {
zoomRect = pointRect
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect)
}
}
mapView.setVisibleMapRect(zoomRect, animated: true)
}
}
这停止了崩溃。我不知道为什么。我正在加载和添加很多注释,但我通过使用进度加载器来调暗背景,确保用户无法与地图交互(如上所述)。
我没有使用任何线程,所有 UI 都在主线程上完成(例如添加注释)
这是来自手机的堆栈跟踪,您可以看到系统正在删除注释(我根本不像上面建议的那样),这是苹果的错误吗?还是我做错了什么?:
型号:iPhone8,1 工艺:
路径:
1.1 (1.0) 代码类型:ARM-64 (Native) 角色:前台 父进程:launchd 3 Coalition:
日期/时间:2018-02-14 17:38:15.3949 +0100 发布时间:
2018-02-14 17:37:10.1854 +0100 操作系统版本:iPhone OS 11.2.5
(15D60) 基带版本:4.30.02 报告版本:104
异常类型:EXC_BAD_ACCESS (SIGSEGV) 异常子类型:
KERN_INVALID_ADDRESS at 0x0000000000000298 VM 区域信息:0x298 是
不在任何地区。以下区域之前的字节:4328635752
区域类型开始 - 结束 [ VSIZE] PRT/MAX SHRMOD 区域详细信息
开始时未使用的空间
--->
__TEXT 000000010201c000-00000001022a0000 [2576K] r-x/r-x SM=COW ...eDiveAdvisor]
终止信号:分段错误:11 终止原因:
命名空间信号,代码 0xb 终止进程:exc 处理程序 [0]
线程触发:0
过滤的系统日志:未找到
线程 0 名称:调度队列:com.apple.main-thread 线程 0
崩溃:0 MapKit 0x000000019650d190
-[MKSpatialCollider insertAnnotationView:] + 244 1 MapKit 0x00000001964791b8 -[MKNewAnnotationContainerView
_updateClusterableAnnotationViews:withID:] + 456 2 MapKit 0x00000001964791b8 -[MKNewAnnotationContainerView
_updateClusterableAnnotationViews:withID:] + 456 3 CoreFoundation 0x0000000185dc51c0 -[__NSDictionaryM
enumerateKeysAndObjectsWithOptions:usingBlock:] + 232 4 MapKit
0x0000000196479d58 -[MKNewAnnotationContainerView
updateAnnotationViewsForReason:] + 296 5 MapKit
0x0000000196549690 -[MKAnnotationContainerView
finishRemovingAnnotationViews] + 32 6 MapKit
0x00000001963c56dc -[MKAnnotationManager updateVisibleAnnotations] +
1616 7 地图套件 0x00000001963c5064
-[MKAnnotationManager 取消选择注释:动画:] + 376 8 MapKit 0x00000001963e4198 -[MKAnnotationManager
_removeAnnotation:updateVisible:removeFromContainer:] + 468 9 MapKit 0x00000001964029ac -[MKMapView removeAnnotation:] + 100 10 MapKit
0x00000001964010b8 -[MKMapView
annotationContainer:requestRemovingClusterAnnotationView:] + 60 11
MapKit 0x0000000196479f8c
__73-[MKNewAnnotationContainerView _updateClusterableAnnotationViews:withID:]_block_invoke + 84 12 MapKit 0x00000001964ac108
__49-[MKAnnotationView _performHideAnimationIfNeeded]_block_invoke.208 + 232 13 UIKit 0x000000018f4ea188 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 764 14 UIKit 0x000000018f4e9afc -[UIViewAnimationState
sendDelegateAnimationDidStop:finished:] + 312 15 UIKit
0x000000018f4e9808 -[UIViewAnimationState animationDidStop:finished:]
+ 296 16 QuartzCore 0x0000000189f4adc4 CA::Layer::run_animation_callbacks+ 1252804 (void*) + 284 17
libdispatch.dylib 0x0000000185876a14
_dispatch_client_callout + 16