我正在使用 iOS 11 的新 API,我已经成功地让集群出现了。现在,我正在尝试更改提供自定义图像的集群图像。由于我创建了这个自定义注释 View :
class PlaceView: MKAnnotationView {
override var annotation: MKAnnotation? {
willSet {
guard let place = newValue as? Place else {return}
clusteringIdentifier = Place.type
image = place.image
}
}
我试图在 willSet block 中添加这一行:
cluster?.image = UIImage(named: "Cluster")
但是没有用。
我错过了什么?谁能指出我正确的方向?
最佳答案
您应该检查注释是否属于 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 What's New with MapKit.
关于ios - 是否可以在 iOS 11 中自定义集群图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47100598/