Oldmicah
Oldmicah

Reputation: 170

kickstarting a touchesMoved/UIPanGestureRecognizer mid-move for a new view

Concept is that a user taps on an icon in a view, a copy of the icon pops up under the user's finger, and they can drag it around until they lift their finger. To do this, I desire the following

  1. icon has touch event
  2. add transparent whole screen UIView and paste a UIImageView containing the icon on it.
  3. track touchMoves or a uiPanGestureRecognizer and move the UIImageView until touch up

The problem is that the touchMoves (and uiPanGestureRecognizer) don't track until the user lifts his finger and puts it back down. i.e. what's happening is:

  1. icon has touch event
  2. add transparent whole screen UIView and add a UIImageView subview containing the icon on it.
  3. user drags finger and nothing happens, so they lift finger and drag again
  4. track touchMoves or a uiPanGestureRecognizer and move the UIImageView until touch up

Apparently, for a UIView to recognize a drag, it seems to have to originate within the UIView. I tried (naively) to just send the touchdown event to the transparent view, but it isn't working.

Any other ideas?

many thanks...

Upvotes: 1

Views: 1119

Answers (2)

John Lemberger
John Lemberger

Reputation: 2699

The trick is to use a single UIPanGestureRecognizer. Add one to your original "icon" (UIView) and use it to detect the initial touch and beginning of the pan. When the UIPanGestureRecognizer enters UIGestureRecognizerStateBegan create the view that will animate the drag. The original icon view and handler will continue to receive callbacks. You can test for UIGestureRecognizerStateChanged and translate the new moving view from within the original handler.

Upvotes: 1

Oldmicah
Oldmicah

Reputation: 170

As far as I can tell, you can't start a drag with any view other than the one the drag was initiated on. For those that have access, take a look at the autoscroll WWDC 2010 project. They basically start a drag on the table cell's view and then allow you to drag that TableCell off the tableview. It works well and will probably be the route I'll be taking.

Upvotes: 1

Related Questions