Disable UITableView scrolling for drag

Hey,


I'm currently implementing UITableViewDragDelegate for an UITableView in my app. From this tableView, I'm dragging out one or multiple cells and I don't want to drop them back in there. When I start the drag and leave my dragging-finger on the tableView, it automatically starts scrolling, like I would expect it to do when I would drop the items back into it. Is there any way to disable the scrolling of the tableView for the drag itself? Setting scrollingEnabled to false doesn't work because I still want to be able to scroll the tableView with my second finger. I just want that the finger that holds the drag doesn't trigger the autoscrolling of the tableView.


Best,
Klemens

Replies

Hey,


thanks for the answer! I already added that method, but returning false still doesn't stop the tableView from scrolling when dragging around into it. I thought that I messed up my tableView in some way, but the same problem occurs adding this method to the sample project from "Adopting Drag and Drop in a Table View".


Best,
Klemens

If someone is experincing the same issue: I digged deeper into the the bug, and here is what I've found out:


My tableView spans over the whole screen, it's content size is veeeery large and it has a bottom content inset of half the screen. No matter which part of the content is currently displayed, as soon as I enter the bottom half of the screen (and thus the size of the bottom content offset) the tableView will start scrolling down automatically. So the point where the autoscrolling begins is directly influenced by the contentInsets, even if they are far away from being displayed. For me, this sounds like a pretty akward bug and I field a radar (33482365)


And the suggested tableView(_:dragSessionAllowsMoveOperation:) does not work, because this has nothing to do with auto scrolling but with allowing an item to be moved instead of copying it when its dropped.

Thanks for posting what you found. Based on that, I was able to get a decent workaround, as I was doing the exact same thing and having the same problem. Here's my workaround in case it helps anyone else:


    func tableView(_ tableView: UITableView, dragSessionWillBegin session: UIDragSession) {
        tableView.contentInset.bottom = 0
    }

    func tableView(_ tableView: UITableView, dragSessionDidEnd session: UIDragSession) {
        tableView.contentInset.bottom = tableView.frame.height / 2.0
    }