2016-12-16 134 views
1

使用下面的代碼,我改變了我的圖釘外觀並從firebase下載了一張圖片。Swift 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:

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

但我不能夠實現在

下載

回答

0

如果您正在點擊某個引腳,則有一個選項是使用代理功能來添加行爲,如更改圖像。

當銷被輕敲,地圖代表將接收該事件,並與

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