是否可以在iOS 11中自定义群集映像?

是否可以在iOS 11中自定义群集映像?,ios,swift,xcode,mapkit,ios11,Ios,Swift,Xcode,Mapkit,Ios11,我正在使用iOS11新的API,我已经成功地使集群出现。现在,我正在尝试更改集群映像,以提供自定义映像。由于我创建了此自定义注释视图: class PlaceView: MKAnnotationView { override var annotation: MKAnnotation? { willSet { guard let place = newValue as? Place else {return}

我正在使用iOS11新的API,我已经成功地使集群出现。现在,我正在尝试更改集群映像,以提供自定义映像。由于我创建了此自定义注释视图:

    class PlaceView: MKAnnotationView {
        override var annotation: MKAnnotation? {
            willSet {
                guard let place = newValue as? Place else {return}
                clusteringIdentifier = Place.type
                image = place.image
            }
    }
我试图在willSet块中添加这一行:

cluster?.image=UIImage(名为:“集群”)

但它不起作用


我错过了什么?有人能给我指出正确的方向吗?

您应该检查注释是否属于
MKClusterAnnotation
类型。如果是,则可以使用
memberAnnotations
属性访问成员批注。例如,在您的情况下,您可以说:

override var annotation: MKAnnotation?
{
    willSet
    {
        if let cluster = newValue as? MKClusterAnnotation { 
            image = UIImage(named: "Cluster")
        } else {
            // set image for non cluster
        }
    }
}

有关更多信息,请参阅WWDC 2017

谢谢您的建议,我完全错过了该链接!然而,我已经能够解决我在探索WWDC的示例项目时遇到的问题:我必须在我的视图控制器中添加这一行:
mapView.register(ClusterView.self,forAnnotationViewWithReuseIdentifier:MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
(我还创建了一个新类来定制集群的MKAnnotationView)注意MKMapView上的新注册方法,因为它有缺陷,所以仍然应该使用MKMapViewDelegate方法:forums.developer.apple.com/thread/89427