问题描述
我正在寻找有关 annotationView 的帮助。我要做的是已经在注释中添加了图标,但是当我要点击注释(图标)时,我希望在注释视图框架中看到按钮,如下所示:
我在旧讨论中寻求帮助,但没有找到答案: UIButton in AnnotationView - How to keep icon and button
这是我的视频:
override func viewDidLoad() {
super.viewDidLoad()
mapView.register(MKMarkerAnnotationView.self,forAnnotationViewWithReuseIdentifier: "identifier") \\ important part
checkLocationServices()
znajdzSzczytyNaMapie(szczyty)
circles = szczyty.map {
MKCircle(center: $0.coordinate,radius: 100)
}
mapView.addOverlays(circles!)
mapView.delegate = self
}
在 viewdidload 中,我在 viewdidload 中添加了 mapView.register(MKMarkerAnnotationView.self,forAnnotationViewWithReuseIdentifier: "identifier")
以注册标识符。
其余代码如下:
func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else { return nil }
//let annotationView = MKMarkerAnnotationView(annotation: annotation,reuseIdentifier: "MyMarker")
let identifier = "identifier"
//guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView else { return nil }
guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier,for: annotation) as? MKMarkerAnnotationView else { return nil }
let btn = UIButton(type: .detaildisclosure)
annotationView.rightCalloutAccessoryView = btn
switch annotation.title!! {
ase "Turbacz":
annotationView.markerTintColor = UIColor(red: 0.86,green: 0.99,blue: 0.79,alpha: 1.00)
annotationView.glyphImage = UIImage(named: "bald")
case "example":
annotationView.markerTintColor = UIColor(red: 0.80,green: 0.98,blue: 0.73,alpha: 1.00)
annotationView.glyphImage = UIImage(named: "bear")
default:
annotationView.markerTintColor = UIColor.green
annotationView.glyphImage = UIImage(named: "gora")
}
return annotationView
}
但我还是明白了:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)