ios - iOS - 选择/取消选择 Apple 地图中的标记不起作用
问题描述
我在地图上选择多个标记。
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView){}
标记选择工作正常,并且正在调用地图委托方法。
- 当标注显示时,我将取消选择显示标注的同一标记。没啥事儿。
- 当标注显示并且我单击任何其他位置然后取消选择前一个标记时,它将取消选择标记。
必需的:
当标注显示时,我将取消选择标注显示需要取消选择的同一个标记。
使用堆栈
xCode
和swift 4.2
Apple
地图套件MKAnnotationView
作为自定义标记
class ArtworkView: MKAnnotationView {
var locItem:LocationItem = LocationItem()
override var annotation: MKAnnotation? {
willSet {
guard let artwork = newValue as? Artwork else {return}
locItem = artwork.locItem
if(!artwork.isUser){
canShowCallout = true
calloutOffset = CGPoint(x: -5, y: 5)
rightCalloutAccessoryView = nil
if let imageName = artwork.imageName {
image = UIImage(named: imageName)
} else {
image = nil
}
detailCalloutAccessoryView = detailLabel
}else{
canShowCallout = false
calloutOffset = CGPoint(x: -5, y: 5)
rightCalloutAccessoryView = nil
image = UIImage(named: "gifcurrentloc")
detailCalloutAccessoryView = nil
}
}
}
解决方案
在showCallout()/hideCallout()
中,
selectAnnotation:/deselectAnnotation:
通过地图使用。
在showCalloutView:
/中,hideCalloutView:
不要调用setSelected:
.
MKAnnotationView
您不应直接调用此方法。MKMapView
对象调用此方法以响应用户与注释的交互。
推荐阅读
- c# - 如何统一排列像“蛇”中的物体?
- storybook - 为 Storybook 侧边栏图标设置主题
- actionscript-3 - Adobe AIR,从 swf 加载的外部 swf 文件无法正确呈现
- python - 通过 selenium 获取未更改的 html
- python - 您可以将 opencv SIFT 与 tensorflow 模型集成吗?
- python - 如何在 vscode 中调试当前模块(使用 -m 参数)?
- angular - 仅包含服务的角度延迟加载模块?
- python - 如何获取列表中附加的非字母和非数字字符?
- python - Pyomo 建模约束中的功率评估错误
- c# - 使用 EF Core 查询联结表