使用下面的代码,我更改了图钉的外观,还从 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
}
但我无法在其中实现下载
最佳答案
如果您正在点击图钉,一种选择是使用委托(delegate)函数然后添加行为,例如更改图像。
当图钉被点击时, map 委托(delegate)将接收事件并处理
optional func mapView(_ mapView: MKMapView,
annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl)
关于ios - Swift Firebase 下载 map 注释上的注释图像单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41175445/