by lilyball · 8y ago · 0 comments
The solution is to use a UILongPressGestureRecognizer with minimumPressDuration set to 0. With this configuration, it will begin recognizing immediately on touch down, allowing you to take action even before the user has moved their finger (or pencil).
I don't have any linkable examples offhand, but at a previous company one of our standard interview questions was to implement custom drag & drop of a view using a gesture recognizer, and our reference app used UILongPressGestureRecognizer because it let us do such nice things as visually "lift up" the view (scale it up slightly and add a drop shadow) the moment your finger touched it.
What's more important is that it's fairly basic usage of UIGestureRecognizer (which is a common thing to need, at least if you're doing any kind of UI development) as well as some basic management of state involving 2 views (the view being dragged, and the destination view it's dropped into).
Interesting though, how do you transition from the instant LongPress into the "Pan" gesture? Or does the LongPress by itself also get the 'moved' events?