Start UIPanGesture event from pressed state during creation

Is there a way to start the UIPanGestureEvent if the finger is already pressed during object creation?

I have a situation where a user is holding their find on the screen, I create a UIView under their finger.

I want them to be able to drag and drop this and this is how I put the UIPanGestureRecognizer inside the UIView.

The problem is I need to take my finger back and put it back in order to trigger the UIPanGestureRecognizer to run. I need it to start from the already pressed state.

Do you know how I can activate a UIPanGesture from an already pressed state, i.e. can I get a touch event that is already active at the time of instantiation and pass it?

+3


source to share


2 answers


You can do this, but the UIPanGestureRecognizer will have to exist already on the view behind the view you created (and you then have to adjust your calculations based on that, not hard).



The reason is that, in the circumstances you described, the touch does not apply to the UIView you are creating - it belongs to the UIView behind it, the one the user originally touched. And given the nature of iOS touchscreen delivery, you can't easily change that. Thus, it will be easier to let this view, the actual original touchscreen, handle that touch.

+2


source


I think Matt's solution is better, so I'm going to mark it as correct.

However, my code structure did not allow me to execute it. The combination of the problem was that the object listener was a UILongGestureRecognizer listener.



So my solution was as follows:

  • Create a callback in my ViewController that will handle the longGestureOverride call

  • Add a callback to the object listening to longGesture that will call the longGestureOverride callback and traverse the point

  • Manually move an object based on a passed point

  • If the user lifts his finger, I disable the longGestureOverride callback and start using the UIPanGesture inside the new object

+2


source







All Articles