【问题标题】:Swift Annotation on Map as Button地图上的 Swift 注释作为按钮
【发布时间】:2016-02-16 00:47:18
【问题描述】:

我尝试给我的注释 3 个按钮(2 个已经完成),图像上的按钮 1 和按钮 2,现在我想在单击按钮 3 后执行一个 segue 无论如何都可以这样做吗?

要创建此注释,我的代码如下所示

if (annotation is CustomPointAnnotation2){

            let reuseId = "ParseAnno"

            var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
            if anView == nil {
                anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                anView!.canShowCallout = true
            }
            else {
                anView!.annotation = annotation
            }

            let buttonSignIcon1 = UIButton()
            buttonSignIcon1.frame.size.width = 50
            buttonSignIcon1.frame.size.height = 52
            buttonSignIcon1.backgroundColor = UIColor(red: 0, green: 0.373, blue: 0.694, alpha: 1.0)
            buttonSignIcon1.setImage(UIImage(named: "annotationButtonLeft"), forState: .Normal)
            anView!.leftCalloutAccessoryView = buttonSignIcon1





            let buttonSignIcon = UIButton()
            buttonSignIcon.frame.size.width = 50
            buttonSignIcon.frame.size.height = 52
            buttonSignIcon.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1.0)
            buttonSignIcon.setImage(UIImage(named: "annotationButtonRight"), forState: .Normal)
            anView!.rightCalloutAccessoryView = buttonSignIcon

            let x = annotation as! CustomPointAnnotation2
            anView!.image = UIImage(named:x.imageName)


            return (anView)

点击我使用的“运行功能”

func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

        if control == annotationView.leftCalloutAccessoryView {

            print(annotationView.annotation?.title)
            print(annotationView.annotation?.coordinate)
            self.Destination_fromAnnotation = (annotationView.annotation?.coordinate)!
            self.getDirections()
        }
.
.
.

有没有办法让按钮“3”也有一个动作?

【问题讨论】:

    标签: ios swift dictionary annotations


    【解决方案1】:

    我认为最好给您的MKAnnotationView 一个包含按钮的子视图。

    如果您可以使用左右标注附件以及 image 属性,那很好,但如果您需要更多,那么最好将所有内容嵌入到您设计的视图中,而不是而不是依赖于很可能用于不同事物的预配置 UI 元素。

    事实上,您的屏幕截图看起来有点蹩脚,尽管它具有三色荣耀,因为草率的对齐和间距,自定义视图的一个例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多