title: Swift (iOS) Create and drag item in one gesture (Passing touch event)
body: <p>I'm trying to create functionality that will allow users to create a new UIView by touching a TableViewCell and then dragging the newly created UIView to another part of the screen where they can drop it.  The problem is, I can accomplish this in two gestures, but for the life of me, I can't figure out how to do it in one gesture.</p>
  
  <p>I've done some extensive reading and I found some promising answers, but none of them seem to work for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/3481858/tutorial-on-how-to-drag-and-drop-item-from-uitableview-to-uitableview">Tutorial on How to drag and drop item from UITableView to UITableView</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18327323/manually-passing-touches-began-to-a-newly-created-instance">Manually passing touches Began to a newly created instance</a></p>
  
  <p>The specific issue that I keep running into, is that the create and drag functionality seems to work while the finger is over the TableViewCell, but as soon as it leaves the cell, the dragging stops and the user is forced to grab the item again, at which point everything works fine.</p>
  
  <p>Each TableViewCell is overriding the touchesBegan function with the following code ('delegate' is the main view controller):</p>
  
  <pre><code>override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
      // Store the touch location
      let touch = touches.anyObject()! as UITouch
      delegate?.touchLocation = touch.locationInView(self.superview!.superview!.superview!)
      // Add a new draggable UIView to the main view
      delegate?.addNewDraggableItem(self)
  }
  </code></pre>
  
  <p>The main view controller has a custom UIView subclass that overrides the hitTest function:</p>
  
  <pre><code>override func hitTest (point: CGPoint, withEvent event: UIEvent?) -&gt; UIView {
      var rv: UIView? = nil
  
      for child in self.subviews as [UIView] {
          if(child.isKindOfClass(DraggableView)) {
              rv = child;
              child.center = point;
              break;
          }
      }
  
      if( rv == nil ){
          rv = super.hitTest(point, withEvent:event)
      }
      return rv!
  }
  </code></pre>
  
  <p>An ideas as to what am I doing wrong?</p>