1

I have a UIView sideMenuView whose child is UIView goToAccountButton

let leftPanSwipe = UIPanGestureRecognizer(target: self, action: #selector(self.sideMenuTranslate))
sideMenuView.addGestureRecognizer(leftPanSwipe)

let goToAccountGestureTap = UILongPressGestureRecognizer(target: self, action: #selector(self.goToAccountGesture))
goToAccountGestureTap.minimumPressDuration = 0.0
goToAccountButton.addGestureRecognizer(goToAccountGestureTap)

When trying to left swipe on goToAccountButton which is a child of sideMenuView, only goToAccountGestureTap works and it doesn't left-swipe at all.

I am unable to understand how to make both UILongPressGestureRecognizer and UIPanGestureRecognizer work on goToAccountButton as expected and so stuck. Please help me find a solution to this. Thank you.

  • Consider priority based implementation in your multi gesture environment. For more info see https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers/preferring_one_gesture_over_another – Ratul Sharker Nov 19 '18 at 13:36
  • https://stackoverflow.com/questions/9272333/combine-longpress-gesture-and-drag-gesture-together – Rukshan Nov 19 '18 at 13:38
  • 2
    increase your minimumPressDuration to 1.0 – guru Nov 19 '18 at 14:28
  • https://stackoverflow.com/questions/41918256/handling-multiple-gesturerecognizers – Abhijith Nov 19 '18 at 15:11

1 Answers1

0

As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add

goToAccountGestureTap.require(toFail: leftPanSwipe)

after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.

NRitH
  • 13,441
  • 4
  • 41
  • 44