Drag and drop from uitableviewcell to uiimage view in ios
I need help implementing drag-and-drop gestures, I would like to know your opinion to find a better approach.
I have a view controller with a uitableview on the right and some kinds of images on the left.
I would like to allow the user to drag and drop each cell of the table view on one of the image views. Basically, drag-n-drop won't work unless the cell is dropped on one of the images, otherwise the image will resize the image to match the dropped cell.
What do you think is the best way to achieve this?
Also, when the user starts dragging, I would like them to be dragging the specific viewport with the image and data, rather than dragging the semi-transparent cell.
source to share
Basic steps for this:
- Add a long gesture recognition ID to your table view (the whole view, not individual cells).
- When the gesture starts, find which cell it ended in (convert point, then custom indexPathForRowAtPoint to get the cell).
- Make a copy of this cell, which will become a draggable view (take a snapshot, add it to the UIImageView and add it to your main view). Or you can pretend to look, however you want, if you don't want it to look like a cell
- make your original cell hidden so that it looks like it is being dragged.
- When changing gestures, move the position of this image based on the locationInView of the gestures)
- Upon completion of the gesture, check if the cell is above the image (hitTest: for this) and perform any animations or calculations you need.
source to share