How to block a gesture from superview to subview?

前端 未结 6 1929
感动是毒
感动是毒 2020-12-30 11:32

I\'m writing a module that everytime I swipe on a view, two sub views with a half size of the view will be added. Those subviews have their own gestures (eg: pan,...). The f

6条回答
  •  無奈伤痛
    2020-12-30 12:03

    Considering that I have a dialogView as a direct subview of my UIViewController's main view I'm attaching a gesture recognizer to the main view and do the following (setting my view controller as the gesture recognizer delegate):

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        let point = touch.location(in: view)
        return !dialogView.frame.contains(point)
    } 
    

提交回复
热议问题