Drag & Drop Works - Autoscroll Doesn't
<p>I have a drag and drop function (code below) for my table that works great. Except, I can't drag a cell to a location not showing on screen / in view. </p>

<p>In other words, I haven't figured out how to make it autoscroll. </p>

<p>Is anyone able to look at my code and know where to add code that enables autoscrolling when the user drags the cell towards the top or bottom of the view?</p>

<pre><code>func animateCellDrag (gestureRecognizer: UIGestureRecognizer, tableView: UITableView, whichList: String) {

    let longPress = gestureRecognizer as! UILongPressGestureRecognizer
    let state = longPress.state
    var locationInView = longPress.locationInView(tableView)
    var indexPath = tableView.indexPathForRowAtPoint(locationInView)
    var count = 0

    struct My {
        static var cellSnapshot : UIView? = nil
    }
    struct Path {
        static var initialIndexPath : NSIndexPath? = nil
    }

    if indexPath != nil {
        //Steps to take a cell snapshot. Function to be called in switch statement
        func snapshotOfCell(inputView: UIView) -&gt; UIView {
            UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0)
            inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
            let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage
            UIGraphicsEndImageContext()
            let cellSnapshot : UIView = UIImageView(image: image)
            cellSnapshot.layer.masksToBounds = false
            cellSnapshot.layer.cornerRadius = 0.0
            cellSnapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0)
            cellSnapshot.layer.shadowRadius = 5.0
            cellSnapshot.layer.shadowOpacity = 0.4
            return cellSnapshot
        }

        switch state {
        case UIGestureRecognizerState.Began:
            //Calls above function to take snapshot of held cell, animate pop out
            //Run when a long-press gesture begins on a cell
            if indexPath != nil {
                Path.initialIndexPath = indexPath
                let cell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!
                My.cellSnapshot  = snapshotOfCell(cell)
                var center = cell.center

                My.cellSnapshot!.center = center
                My.cellSnapshot!.alpha = 0.0

                tableView.addSubview(My.cellSnapshot!)

                UIView.animateWithDuration(0.25, animations: { () -&gt; Void in
                    center.y = locationInView.y

                    My.cellSnapshot!.center = center
                    My.cellSnapshot!.transform = CGAffineTransformMakeScale(1.05, 1.05)
                    My.cellSnapshot!.alpha = 0.98

                    cell.alpha = 0.0

                    }, completion: { (finished) -&gt; Void in

                        if finished {
                            cell.hidden = true
                        }
                })
            }
        case UIGestureRecognizerState.Changed:

            if My.cellSnapshot != nil || indexPath != nil {
                //Runs when the user "lets go" of the cell
                //Sets CG Y-Coordinate of snapshot cell to center of current location in table (snaps into place)
                var center = My.cellSnapshot!.center
                center.y = locationInView.y
                My.cellSnapshot!.center = center

                let appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
                let context: NSManagedObjectContext = appDel.managedObjectContext!
                let fetchRequest = NSFetchRequest(entityName: whichList)
                let sortDescriptor = NSSortDescriptor(key: "displayOrder", ascending: true )
                fetchRequest.sortDescriptors = [ sortDescriptor ]

                //If the indexPath is not 0 AND is not the same as it began (didn't move): Update array and table row order
                if ((indexPath != nil) &amp;&amp; (indexPath != Path.initialIndexPath) &amp;&amp; (indexPath?.row &lt; taskList_Cntxt.count)) {

                    switch whichList {
                        case "TodayTask", "TomTask", "TBDTask", "FinTask":
                            swap(&amp;taskList_Cntxt[indexPath!.row], &amp;taskList_Cntxt[Path.initialIndexPath!.row])
                            tableView.moveRowAtIndexPath(Path.initialIndexPath!, toIndexPath: indexPath!)
                            toolBox.updateDisplayOrder()
                        default:
                            swap(&amp;curLifeList_Context[indexPath!.row], &amp;curLifeList_Context[Path.initialIndexPath!.row])
                            tableView.moveRowAtIndexPath(Path.initialIndexPath!, toIndexPath: indexPath!)
                            toolBox.llvc_updateDisplayOrder()
                    }

                    do {
                        try context.save()
                    } catch _ { print("Drag and drop error. State: Changed")}

                    Path.initialIndexPath = indexPath
                }
            }
        default:
            if My.cellSnapshot != nil || indexPath != nil {
                //Runs continuously while a long press is recognized / Animates cell movement
                let cell = tableView.cellForRowAtIndexPath(Path.initialIndexPath!) as UITableViewCell!

                cell.hidden = false
                cell.alpha = 0.0
                UIView.animateWithDuration(0.25, animations: { () -&gt; Void in
                    My.cellSnapshot!.center = cell.center
                    My.cellSnapshot!.transform = CGAffineTransformIdentity
                    My.cellSnapshot!.alpha = 0.0
                    cell.alpha = 1.0
                    }, completion: { (finished) -&gt; Void in
                        if finished {
                            //Completion block removes snapshot of cell, cleans everything up
                            Path.initialIndexPath = nil
                            My.cellSnapshot!.removeFromSuperview()
                            My.cellSnapshot = nil
                        }
                })//End of competion block &amp; end of animation
            }//End of 'if nil'
        }//End of switch
    }//End of longPress if-nil
}//End of longPressGestureRecognized
</code></pre>