4

I have an area of my screen on which I want to recognize a long press. I use a UILongPressGestureRecognizer.

Once the long press event happens, I show a custom UIView that has a touchesMoved method, by adding it as a subview. This custom UIView is added right in the center of where the long press event happened, it is right under my finger.

Problem: If I'm continuously holding my finger after the long press, the touchesMoved on the custom UIView is not called. Only when I lift my finger and touch again is the touchesMoved method recognized.

Any possible solutions? I believe the problem is that when the touch started, it originated from the underlying view. Even though I add a new UIView on top of the hierarchy and move my finger over it, it is not recognized, ie touchesMoved is not called because the view went into the hierarchy already after the touches have began.

I've tried a couple of things to cancel the long press gesture recognizer but nothing seems to be working. Thanks.

rafalio
  • 3,928
  • 4
  • 30
  • 33
  • Can you try adding touchesMoved on your parent view and call public methods of the child and do what needs to be done? Just thinking aloud. – Gurtej Singh Aug 09 '15 at 06:41
  • @GurtejSingh I guess I could, but I want my custom UIView to be library-like. Ie, you should be able to plug-and-play it, the parent shouldn't be responsible for passing touch events down to it. Anyways, thanks for the input. – rafalio Aug 09 '15 at 19:08
  • Absolutely. I understand. Hope we find an answer soon :) – Gurtej Singh Aug 09 '15 at 19:09
  • Try setting the parent view.clipToBounds = NO and run it. If your subview is outside of the frame of the parent view, it will not get the touch events. Setting clipToBounds = NO will make your subview disappear if this is the case. – Dan Loughney May 31 '17 at 00:18
  • Did you find any solution to this ? – Swasidhant Jan 26 '20 at 09:27

0 Answers0