How to add touch gesture to map but ignore touches on pins and annotations?

后端 未结 2 1778
孤街浪徒
孤街浪徒 2021-01-05 05:57

I have a mapview that uses MKCircles to display radius information for certain user actions.

What I want to do, is allow the user to dismiss the M

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 06:12

    This is my Swift 2.1 compatible version:

    func didTapOnMap(recognizer: UITapGestureRecognizer) {
        let tapLocation = recognizer.locationInView(self)
        if let subview = self.hitTest(tapLocation, withEvent: nil) {
            if subview.isKindOfClass(NSClassFromString("MKNewAnnotationContainerView")!) {
                print("Tapped out")
            }
        }
    }
    

    MKNewAnnotationContainerView is a private inner class, so you cannot compare directly like:

    if subview is MKNewAnnotationContainerView {
    }
    

提交回复
热议问题