【问题标题】:Swift Firebase download annotations images on map annotation clickSwift Firebase 下载地图注释上的注释图像点击
【发布时间】:2016-12-16 00:15:40
【问题描述】:

通过下面的代码,我改变了我的 pin 的外观,并从 firebase 下载了一个图像。

问题是我需要仅在按下 pin 时才下载图像,而现在这一切都是一次。

谁能告诉我如何检测按下的 pin 并只下载他的图像?

我是编程新手...

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        if !(annotation is SxAnnotations){
            return nil
        }

            // If no pin view already exists, create a new one.
            let annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
            annotationView.pinTintColor = .green
                annotationView.animatesDrop = true
            annotationView.canShowCallout = true
            // Because this is an iOS app, add the detail disclosure button to display details about the annotation in another view.


        let sxAnnotations = annotation as! SxAnnotations

        let downloadURL = sxAnnotations.image!

        storageRef.storage.reference(forURL: downloadURL).data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
                    let image = UIImage(data: data!)

                annotationView.detailCalloutAccessoryView = UIImageView(image: image)
                    let rightAccessory = UILabel(frame: CGRect(x:0,y:0,width:50,height:30))
                    rightAccessory.text = sxAnnotations.name!
                    rightAccessory.font = UIFont(name: "Verdana", size: 10)
                    annotationView.rightCalloutAccessoryView = rightAccessory

            })
        return annotationView;
        }

编辑:我知道有一个函数:

func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!)
{
    //Pin clicked, do your stuff here
}

但我无法在其中实现下载

【问题讨论】:

    标签: ios swift firebase mapkit firebase-storage


    【解决方案1】:

    如果您正在点击图钉,一种选择是使用委托函数来添加行为,例如更改图像。

    当 pin 被点击时,地图代理将接收事件并被处理

    optional func mapView(_ mapView: MKMapView, 
           annotationView view: MKAnnotationView, 
           calloutAccessoryControlTapped control: UIControl)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多