2016-03-08 23 views
0

我在地圖上添加了註釋並添加了標題,leftCalloutAccessoryView(ImageView)和rightCalloutAccessoryView(UIButton),當點擊按鈕播放音頻時,我不想點擊按鈕,當我將標註在任何開始播放音頻的區域。如何使整個調用可打開?

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 

    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("AnnotationImage") 
    if annotationView == nil { 
     if annotation.isKindOfClass(Annotation) { 

      annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationImage")    

      annotationView?.rightCalloutAccessoryView = self.playButton() // Custome button for rightCallOut. 
      annotationView?.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "annotationPinImage")) 
      annotationView?.image = UIImage(named: "annotationPinImage.pdf")  
      annotationView?.canShowCallout = true 
      annotationView?.userInteractionEnabled = true  
    } else {  
     annotationView?.annotation = annotation  
    } 
    return annotationView  
} 

//播放按鈕的方法:

func playButton() -> UIButton {  
    let image: UIImage = UIImage(named: "BtnPlayAudio.pdf")!  
    let button: UIButton = UIButton(type: .Custom)  
    button.frame = CGRectMake(0, 0, image.size.width, image.size.height)  
    button.setImage(image, forState: .Normal)  
    return button  
} 

在此先感謝。

回答

1

添加手勢識別器...未經測試,讓我知道它是否工作?我用雙擊會導致一個單一的火會很容易...

注意tapGestureRecognizer最終可能需要是一個類變量。

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapped:") 
tapGestureRecognizer.numberOfTapsRequired = 2 
annotationView.addGestureRecognizer(tapGestureRecognizer) 

func tapped(sender: UITapGestureRecognizer) 
{ 
    print("tapped ",sender) 
    // play sound 
} 
+0

它的工作,但有一個問題。當我在顯示標註之前點擊註解時,此方法也在調用。 –

+0

看@「發件人」,也許你可以根據這個來確定要撥打哪個電話。 – user3069232

+0

或更好的嘗試使用長按來代替水龍頭。 – user3069232

相關問題