Begin UIPanGesture Event From A Pressed State At Time Of Instantiation

ぐ巨炮叔叔 提交于 2020-01-14 22:53:16

问题


Is there a way to begin a UIPanGestureEvent if the finger is already pressed at the time the object is instantiated?

I have a situation where when a user holds their find on a screen I create a UIView under their finger.

I want them to be able to drag that around and as such I have put a UIPanGestureRecognizer inside the UIView.

Problem is I need to take my finger off and put it back to trigger the UIPanGestureRecognizer to start up. I need it to start from an already pressed state.

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


回答1:


You can do it, but the UIPanGestureRecognizer will need to exist already on the view behind the view you create (and you will then have to adjust your calculations based on this; not difficult).

The reason is that, under the circumstances you describe, the touch does not belong to the UIView you create - it belongs to the UIView behind it, the one that the user was originally touching. And given the nature of iOS touch delivery, you can't readily change that. So it will be simpler to let that view, the actual original touch view, do the processing of this touch.




回答2:


I think Matt's solution is best so I am going to mark it as correct.

However my code structure wasn't going to allow me to cleanly implement it. Compounding the issue was the object listening was listening for a UILongGestureRecognizer.

So my solution was as follows:

  1. Create a callback in my ViewController that would handle the longGestureOverride call

  2. Add a callback to the object listening for the longGesture that would call the longGestureOverride callback and pass along the point

  3. Manually move the object based on the point passed back

  4. If the user lifts their finger, I disable the longGestureOverride callback, and begin using the UIPanGesture inside the new object



来源:https://stackoverflow.com/questions/27790899/begin-uipangesture-event-from-a-pressed-state-at-time-of-instantiation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!