Swift Firebase在地图注释上单击下载注释图像

时间:2016-12-16 00:15:40

标签: ios swift firebase mapkit firebase-storage

使用下面的代码我改变了我的引脚的外观,并从firebase下载了一张图片。

问题是我需要只在按下一个引脚时才下载图像,而现在只需一次就可以了。

有人可以告诉我如何检测按下的图钉并仅下载他的图像?

我是编程新手......

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
}

但是我无法在那个

中实现下载

1 个答案:

答案 0 :(得分:0)

如果您正在点击一个图钉,一个选项是使用委托功能然后添加行为,例如更改图像。

点击图钉时,地图代表将收到该事件,并以

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