我在地图上选择多个标记。标记选择工作良好,映射委托方法。
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView){}正在被呼叫。
必需:
当标注显示,我将取消选择相同的标记,其标注显示需要取消选择。
使用堆栈
xCode与swift 4.2Apple MapKitMKAnnotationView作为自定义标记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
}
}
}发布于 2019-04-28 11:41:45
在showCallout()/hideCallout()中,通过地图使用selectAnnotation:/deselectAnnotation:。
在showCalloutView:/hideCalloutView:中,不要在MKAnnotationView上调用setSelected:。
不应直接调用此方法。MKMapView对象响应与注释的用户交互调用此方法。
发布于 2019-05-02 10:55:49
您应该尝试使用方法deselectAnnotation使用您的mapView outlet来实现它,例如:
mapView?.deselectAnnotation(annotation: yourAnnotation, animated: false)https://stackoverflow.com/questions/55850586
复制相似问题