【发布时间】:2018-12-31 14:41:57
【问题描述】:
我正在开发一个 iOS swift 应用程序,该应用程序将图像显示为地图上的注释。当多个注释重叠时,它们应该聚集在一起,而不是显示为一张图像。
Apple 提供的集群有时不起作用。缩小并多次放大时,图像可能会重叠很多。
它应该是这样的:
这是发生错误时的样子:
我已将示例视频上传到 Youtube (https://youtu.be/kaI0bTS8_HY)
关于实现的一些细节:
-
我正在使用专门的 MKAnnotationView:
class PhotoAnnotationView: MKAnnotationView { let annotationWidth = 100 var imageView = UIImageView() override init(annotation: MKAnnotation?, reuseIdentifier: String?) { super.init(annotation: annotation, reuseIdentifier: reuseIdentifier) clusteringIdentifier = "LocatedPhoto" collisionMode = .circle addSubview(imageView) imageView.frame = annotationFrame frame = annotationFrame } var annotationFrame: CGRect { return CGRect(x: 0, y: 0, width: annotationWidth, height: annotationWidth) } override var annotation: MKAnnotation? { willSet { if let annotation = newValue as? PhotoAnnotation { let url = annotation.locatedPhoto.thumbnailURL let displayLocation = annotation.displayLocation setImage(url: url) } } } func setImage(url: URL) { //... } }
MapViewController 注册了这个注解类型来显示注解:
mapView.register(PhotoAnnotationView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
省略,因为我认为这不是问题的根源: - MKClusterView(常规 ClusterView 也存在错误) - 在地图视图中添加注释
这个问题的根源是什么?
【问题讨论】:
标签: ios swift mapkit mkannotation mkannotationview