UIGestureRecognizer blocks subview for handling touch events

后端 未结 10 1084
北恋
北恋 2020-11-28 19:32

I\'m trying to figure out how this is done the right way. I\'ve tried to depict the situation: \"enter

10条回答
  •  误落风尘
    2020-11-28 19:47

    implement a delegate for all the recognizers of the parentView and put the gestureRecognizer method in the delegate that is responsible for simultaneous triggering of recognizers:

    func gestureRecognizer(UIGestureRecognizer,       shouldBeRequiredToFailByGestureRecognizer:UIGestureRecognizer) -> Bool {
    if (otherGestureRecognizer.view.isDescendantOfView(gestureRecognizer.view)) {
        return true
        } else {
        return false
    }
    

    }

    U can use the fail methods if u want to make the children be triggered but not the parent recognizers:

    https://developer.apple.com/reference/uikit/uigesturerecognizerdelegate

提交回复
热议问题