简体   繁体   English

如何使整个呼叫可点击?

[英]How to make whole call out tappable?

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. 我在地图上添加了注释,并添加了标题,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    
}

// 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     
}

Thanks in advance. 提前致谢。

Add a gesture recogniser... untested, let me know if it works? 添加手势识别器...未经测试,请告知它是否有效? I used a double tap cause a single will fire too easily... 我用了两次水龙头,因为单发火太容易了。

Note the tapGestureRecognizer may need to be a class variable ultimately. 请注意,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.

相关问题 如何使整个MKPinAnnotationView可以轻敲,而不仅仅是正确的附件视图 - How to make a whole MKPinAnnotationView tappable, not just right accessory view 如何在NSAttributedString中建立可点击的链接 - How to make tappable links in NSAttributedString SwiftUI 2.0 List with children - 如何让显示按钮的可点击区域覆盖整个列表项 - SwiftUI 2.0 List with children - how to make the tappable area of the disclosure button cover the whole list item 使视图可拖动但不可点击 - Make view draggable but not tappable 使自定义注释成为可点击的 - Make Custom Annotations tappable SwiftUI 如何制作可点击的行和动画文本可见性? - SwiftUI how to make tappable row and animate text visibility? 如何在屏幕上设置动画时使UIImageView可以进行播放 - how to make a UIImageView tappable while it is animating across the screen 如何使可点击的NSAttributedString移动到另一个ViewController Swift - How to make tappable NSAttributedString Move To Another ViewController Swift 如何使 navigationBarTitle 和 navigationBarItem 的重叠区域可点击 - SwiftUI - How to make the overlap area of navigationBarTitle and navigationBarItem tappable - SwiftUI Swift & UILabel:我们如何为条款和条件制作内联的可点击文本? - Swift & UILabel: How do we make inline tappable texts for terms and condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM