如何使整个叫唤tappable? [英] How to make whole call out tappable?
问题描述
我添加注释地图并添加标题,leftCalloutAccessoryView(ImageView的),和rightCalloutAccessoryView(UIButton的),当按钮点击该播放音频,我想,而不是敲击按键的时候我会顶上标注开始播放任何区域音频。
I have added annotation on map and added title, leftCalloutAccessoryView (ImageView), and rightCalloutAccessoryView (UIButton), When tap on button it plays audio, I want instead of tapping on button when i will top on callout any area it starts playing audio.
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
}
//播放按钮的方法:
// Play Button methods:
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
}
先谢谢了。
推荐答案
添加一个手势识别器...未经检验的,让我知道,如果它的工作原理?我用了一个双击会导致一个必火太容易...
Add a gesture recogniser... untested, let me know if it works? I used a double tap cause a single will fire too easily...
注意tapGestureRecognizer可能需要一类变量大势所趋。
Note the tapGestureRecognizer may need to be a class variable ultimately.
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapped:")
tapGestureRecognizer.numberOfTapsRequired = 2
annotationView.addGestureRecognizer(tapGestureRecognizer)
func tapped(sender: UITapGestureRecognizer)
{
print("tapped ",sender)
// play sound
}
这篇关于如何使整个叫唤tappable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!