簡體   English   中英

如何使整個呼叫可點擊?

[英]How to make whole call out tappable?

我在地圖上添加了注釋,並添加了標題,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     
}

提前致謝。

添加手勢識別器...未經測試,請告知它是否有效? 我用了兩次水龍頭,因為單發火太容易了。

請注意,tapGestureRecognizer最終可能需要是類變量。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM