4 ms·
Admittedly you do lose the convenience methods from UIPanGestureRecognizer (sure would be nice if Apple would add them to UILongPressGestureRecognizer too), but
by eridius 8y ago
Admittedly you do lose the convenience methods from UIPanGestureRecognizer (sure would be nice if Apple would add them to UILongPressGestureRecognizer too), but you can recover translation just by grabbing the location of the recognizer in the associated view when the state moves to .began and then subtracting that from the current location on every subsequent .changed state callback. Calculating velocity is harder of course, but you could do it without too much difficulty by recording the previous location and timestamp and using that to calculate an instantaneous velocity (I'm not sure if this is what UIPanGestureRecognizer does or if it tries to smooth the velocity at all using multiple "frames").
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.
- dangwu 8y agoThat’s an incredibly specific interview question... there’s a lot more to iOS development than drag and drop. How has it fared for you?
- eridius 8y agoActually quite well. The fact that it's drag & drop is pretty irrelevant, except in that it's not something the interviewee has likely done before because it's not a very common thing to interrupt. 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).
- eridius 8y agos/interrupt/implement/