There is no built-in method that you suggest. What you want can be done, but you will have to process it using a gesture recognizer and appropriate code to handle the drag and drop operation.
I tried to use a subclass for this and finally came back to put it in my controller. In my case, however, I was dragging things to / from the collection view, as well as two other views on the screen.
I don’t know if you have a book, but the most useful thing I found is the Erica Sadun Core iOS6 Develper Cookbook, which has excellent drag and drop code in Collection Views. I don’t think that this specifically concerns dragging outside the CV, but for me the solution was to put the gesture recognizer in the general supervisor and always use its coordinates, not the coordinates of the subview.
One of the problems I ran into was that I wanted to be able to select cells with a tap, as well as drag and drop, and there is no way (despite Apple's documents opposite) to require that one gesture gesture not be executed in the view collection. As a result, I had to use a long press gesture to complete the whole operation, and there is no translation of InView for a long press (there is locationInView), so additional work is required:
iOS - gesture recognition converter translationInView
Another thing that will make it more difficult or simpler is the number of possible drops goals. I had many different views (straight UIView, collectionview and scrollViews). I found it necessary to keep a list of “drop targets” and check for intersections with targets when moving the drag object. One way or another, you should be able to determine if the view you are crossing is the place where the fall can occur.
If you are referring to a specific situation of dragging something from the view to remove it (for example, dragging to the trash can view), and this should not be difficult. You must remember that when you do the transformation, your frame becomes meaningless, but the center is still good; so you end up using the center for everything you usually use for the frame.
Here is the closest thing I found on the Internet that was useful; I have not finished using this class, although, as I thought, it would be too difficult to implement in my application.
http://www.ancientprogramming.com/2012/04/05/drag-and-drop-between-multiple-uiviews-in-ios/
Hope this was some help.
source share