2016-12-16 11 views
1

以下のコードでは、私のピンの外観を変更し、firebaseから画像もダウンロードします。Swift Firebase Downloadアノテーション画像を地図上に表示アノテーションをクリック

問題は、ピンが押されたときにのみイメージがダウンロードされる必要があるということです。代わりに、これはすべて一度に表示されます。

ピンを検出して画像をダウンロードするにはどうすればいいですか?

私はプログラミングに新たなんだ...

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) 
で処理されます
関連する問題