ios - Swift Firebase 下载 map 注释上的注释图像单击

标签 ios swift firebase mapkit firebase-storage

使用下面的代码,我更改了图钉的外观,还从 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/

相关文章:

ios - 以编程方式全屏打开 iframe 视频

ios - 将 View 从其原点旋转到另一个 View

ios - 我想要一个 UIView 覆盖整个屏幕甚至导航栏,但显示它的 subview

ios - 通知中心测试推送发送时出现 APNS 错误 channel 错误

ios - xcode swift Storyboard引用不起作用

swift - 我的滚动虽然通常很顺利,但有时会很不稳定

email - 从 Firebase webapp 发送邮件

swift - 当我希望 Cloud Firestore 快速创建数组时创建 map

javascript - Firestore——仅获取大型同步集合中已更改的文档

ios - Objective-C: block 中的动画