iPhone: Detecting Tap in MKMapView

后端 未结 8 1394
天命终不由人
天命终不由人 2020-12-24 07:35

How do I detect a single tap on an instance of MKMapView? Do I have to subclass MKMapView and then override the touchesEnded method?

8条回答
  •  生来不讨喜
    2020-12-24 08:06

    my 2 cents for swit 5.x:

    override func touchesEnded(_ touches: Set, with event: UIEvent?) {
        if let touch = touches.first {
            let v = touch.view
            let ssv = v?.superview?.superview
            if ssv === self.mapView{
                searchBar.resignFirstResponder()
            }
        }
    }
    

    it works. but honestly can break if apple changes layers of views. better a recognizer.

提交回复
热议问题