swift - 更改注释视图按钮

问题描述

我正在寻找有关 annotationView 的帮助。我要做的是已经在注释中添加了图标,但是当我要点击注释(图标)时,我希望在注释视图框架中看到按钮,如下所示:

enter image description here

点击后,我想看到这个白框和 uibutton:

enter image description here

我在旧讨论中寻求帮助,但没有找到答案: 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
}

但我还是明白了:

enter image description here

而不是这个:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...