drag and drop from uitableviewcell to uiimage view in ios - iphone

I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach.
I have a view controller with a uitableview on the right and some image views on the left.
I would like to allow the user to drag every cell of the table view on one of the image views. Basically the drag-n-drop will fail if the cell is not released on one of the image views, otherwise the image view will change image according to the dropped cell.
What do You think is the best way to achieve this?
In addition, when the user start dragging, I would like that he drags around a particular shaped subview, with image and data, not drag the semitransparent cell.
Thanks,

The basic steps for this would be:
Add a long press gesture recognizer to your table view (the whole view, not individual cells)
When the gesture begins, find which cell it is over (convert point, then user indexPathForRowAtPoint to get the cell)
Make a copy of that cell which will become the dragged view (take a snapshot, add it to a UIImageView and add that to your main view). Or you could make the view look however you want if you dont want it to look like the cell
make your original cell hidden so it looks like it is being dragged
On gesture changed, move teh position of this image view based on locationInView of the gesture)
On gesture ended, check to see if the cell is over an image (hitTest: for this) and do any animations or calculations you need.

Related

Drag UITableView or all TableViewCells to display a label

I'd like to create make a table view go to left when we swipe with a pan gesture. The goal is to display a label a the right of the table view like Instagram or iMessage for instance. Does anyone have a tip for creating this?
The result I would like to get.
https://i.stack.imgur.com/kDdSa.jpg
As a rough sketch, you may place a subview containing a timestamp inside your cell, below or to the side of the main subviews that display the content. You also will need to write a method that, depending on the pan progression, will show/hide this timestamp. Then you add a pan gesture recognizer to the table view itself, and, once panning, in your handler method you can call this disclosure method on the visible cells.

Overlaying buttons on tableviewcell with collectionview inside

I have implemented a image slider with a UICollectionView inside a UITableViewCell which the user can slide to left and right. I want to create two buttons on this UITableViewCell so the user can also tap on that buttons to slide the images.
I've done this by adding the buttons on the images inside the UICollectionViewCells but with that the buttons also are swiping when the user swipes to left or right or taps the buttons.
I tried to fix the buttons on the UITableViewCell, but anyhow the buttons does not get displayed, when I do it like this.
So how can I achieve this, that the buttons are fixed inside the UITableViewCell and the UICollectionView inside the UITableViewCell can move it cells without effecting these two slider buttons?
At storyboard it looks like this:
Can't rearrange the buttons:
Add the buttons directly to the content view of the table view cell, don't add them to the collection view. That way they will stay in position. If you can't see them it's possible that they were underneath the collection view and were obscured. Change the order of the views in interface builder by dragging and dropping in the document outline. This changes which view is on top.
The document outline is the view you have posted as a screenshot in your question, starting at "brandsCollectionTableViewCell". The outline contains the subviews of the cell. Views with the same parent, like the image view, label and buttons currently shown in the outline, will be ordered "on top" of each other by their position in the list. So you drag the items in that list to change the order, or select the buttons then go to Editor -> Arrange -> Send XX to adjust the position.
Use the Xcode view hierarchy debugger to help you understand what is happening (that's this button on the debugging toolbar):
The 3D view will let you see where your "missing" buttons are.
If you really want to include the buttons in the collection view, then you need to use a custom collection view layout implementing floating views. That's not a straightforward task, but I've written something about it here.

UITableView: Drag a row onto another one

I have a UITableView that represents a list of objects, I'd like the user to touch an object, drag it onto another one (as to combine them) and seeing the two disappearing and a new one appearing. I guess that I can't do this with the standard table view editing methods (a row cannot be dragged onto another one, am I right?). Shall I write my touch listeners? how can I do that?
I managed to find a workaround: after the first click on a custom UITableCellView I create a new UIView to put on top of the window that intercepts another touch+drag.
The other touch creates a UIImageView that copies the undelying clicked cell as a Image. This UIImageView can be dragged around along the UIView and then dismissed when necessary.
When I end the touch I look if it ended up a another cell, if so I get its indexPath and compute a coherent action

iPhone: How to Place a Scrollview Inside of Tableview Cell

I want to put a scroll view inside of the table view cell. I have a number of buttons in one cell of table view and I need to scroll that cell to show the appropriate button.
If you want to use a vertical scroll view then I wouldn't suggest you doing it because, as TechZen wrote, there will be a mess in this case.
If you want the inner scroll view to scroll horizontally then it might be achieved by 2 ways:
Implement a custom table view cell that will include a scroll view inside it.
Add a scroll view as a sub-view to your cell that you will return from tableView:cellForRowAtIndexPath: method.
I suggest you to use the second approach.
There are plenty of examples online. Usually the sub-views are labels or image views, but it is not complicated at all to add a scroll view instead...
I don't think you can do this. It would require nesting of scrollviews which isn't really supported.
Even if it was, it would be very difficult for a user to know which scrollview they were hitting with their pudgy finger. Remember, you don't have the one pixel precision of a mouse on the iPhone. You have an area of at least 15x15 pixels. You don't have a scroll bar but instead just drags anywhere on the screen.
Instead, you should use a master-detail pattern. Selecting the cell in the tableview pushes a detail view which has the scroll view with all the buttons.
Why do you want to do it like this?
I think the best idea is to draw your table view manually above your uiscrollview. I did it, and it works. It just takes more effort and drawing accuracy. But that takes a lot of time. :)

How do you drag-and-drop from a TableView's icon to a stationary icon?

How do we go about coding drag-and-drop (or tap-and-drag) from a cell in a TableView on an iPhone? I'd like to have a set of drop destination icons that are stationary. I've been trying touchesBegan, touchesMoved and touchedEnded methods. These events fire nicely from a View so I can get a swipe to work nicely. Most likely the destination icons will be in a View so I think we are trying to get the drag-and-drop to begin in a TableView cell and end on an icon on a View that is beside the TableView.
Are you trying to drag the entire UITableViewCell, or a UIView inside the cell? Either way, I don't think you'll be able to move the view outside the bounds of its parent, which would be the UITableView.
I have another project where I have a icon or tile (UIImageView) that the user can drag around the screen. After it reaches a certain distance, it snaps back.
Similarly, a possible solution might involve popping up a UIView (perhaps a UIImageView) over top of the table cell when the cell is tapped. The user could drag that around the screen, and you could make it disappear when it's "dropped" on whatever target you have.