微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift - 更改注释视图按钮

如何解决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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?