user339946
user339946

Reputation: 6119

Passing a touch gesture

I'm looking for a solution to help "pass" a touch gesture along.

Basically I have a menu, and I want users to be able to drag and drop items from the menu to the canvas in a single continuous drag.

I have already achieved a draggable image via pan gestures (we'll call these instances Sprites). I can also instantiate a Sprite anywhere on the UIView using a button or UIImageView with touch gestures.

However, this currently requires two touches. One to touch down the menu item button and release, creating the Sprite. The second to touch down on the sprite, allowing the user to drag it, and then release it where they want. I would like to merge these touches so that when a user touches a menu item, the Sprite is instantiated and already within the pan gesture, or something to that affect.

I've attached a visual description if that helps. Any help is appreciated. Thanks!

enter image description here

Upvotes: 2

Views: 1904

Answers (1)

Cyprian
Cyprian

Reputation: 9453

There is no way of artificially forcing UIGestureRecognizer to recognize touches that are passed to a different view.

From the Gesture Recognizer docs:

Delivery of events initially follows the usual path: from operating system to the application object to the window object representing the window in which the touches are occurring. But before sending an event to the hit-tested view, the window object sends it to the gesture recognizer attached to that view or to any of that view’s subviews. Figure 3-1 illustrates this general path, with the numbers indicating the order in which touches are received.

Figure 3-1

enter image description here

Event's delivery happens automaticaly by the system and is delivered to the appropriate view.

To do what you want I would implement the UIGestureRecognizer on the subview (view that contains your UIButton) and on press create an instance of your Sprite object and manipulate that object from withing the gesture recognizer of the subview. Alternatively you could use -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)even to reposition the object yourself.

Upvotes: 4

Related Questions