如何使整个呼叫可点击? [英] 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
}
//播放按钮方法:
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
}
这篇关于如何使整个呼叫可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文