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     
}

提前致谢。

4

1 回答 1

1

添加手势识别器...未经测试,让我知道它是否有效?我用了双击,因为一个会很容易触发...

请注意,tapGestureRecognizer 最终可能需要成为类变量。

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

func tapped(sender: UITapGestureRecognizer)
{
    print("tapped ",sender)
    // play sound
}
于 2016-03-08T05:18:49.767 回答