我有一个带有mapview的简单屏幕,在上面以典型方式添加了两个自定义注释。现在我需要返回并在发生某些事件时更改图像;本质上只是更改图像以显示一个小标志,指示特定注释具有更多可供用户选择点击的数据。
我想做的是删除有问题的注释,将其所有数据复制到带有新图像的新图像中,然后重新添加,从而使用viewFor注释并检查用于注释基础数据的更新性质。似乎有点过劳。
没有办法简单地说:
for var ann in self.eventMap.annotations {
if let ann2 = ann as? CustomPointAnnotation { // custom type with properties
if "myCustomIdValueHere" == ann2.myCustomId {
// found it.
print( "Found the one I'm looking for" )
// then change its image from "[existingImageName]" to "[existingImageName]Attention"
}
}
}
答案 0 :(得分:2)
您可以使用view(for:)方法获取特定的MKAnnotationView。尝试以下代码:
for var ann in self.eventMap.annotations {
if let ann2 = ann as? CustomPointAnnotation { // custom type with properties
if "myCustomIdValueHere" == ann2.myCustomId {
// found it.
print( "Found the one I'm looking for" )
// then change its image from "[existingImageName]" to "[existingImageName]Attention"
let annotationView = self. eventMap.view(for: ann2)
annotationView?.image = UIImage(named: "[existingImageName]Attention") }
}
}