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



在下面的代码上,我更改了我的销钉的外观,还从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
}

但我无法在该下载

中实现下载

如果要敲击别针,一个选项是使用委托功能来添加行为,例如更改图像。

敲击引脚时,地图委托将接收事件并使用

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

最新更新