MKAnnotationView and tap detection

前端 未结 6 1202
攒了一身酷
攒了一身酷 2020-12-09 21:29

I have a MKMapView. I added a UITapGestureRecognizer with a single tap.

I now want to add a MKAnnotationView to the map. I can

6条回答
  •  有刺的猬
    2020-12-09 21:36

    It'd be much easier if we just test the superviews of the touch.view in the gesture delegate:

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        var tv = touch.view
        while let view = tv, !(view is MKAnnotationView) {
            tv = view.superview
        }
        return tv == nil
    }
    

提交回复
热议问题