how to drag or drop multi uitableveiwcells on ios? - ios

I want do drag a lot of selected cells and recorder them in my app.But I don't know how to do it.It seems apple just let u to drag one that what I have done it.
idea?

If it is ok to require that the selected cells are contiguous, then you can cheat by replacing them with a single tall cell.
EDIT:
For noncontiguous, the lazy solution would be to let the user select any cells, then after they drag and drop one of them, just move all the other selected cells right below it.
You could experiment with UITableView and see if it will let you animate out the other selected cells (with deleteRowsAtIndexPaths:withRowAnimation:) as soon as dragging is detected (possibly with UITableViewDelegate's tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:). You could also see if it will let you redraw/resize the cell when it begins dragging - then you could make it look like a z-layered stack or totem pole them into a tall cell while dragging.
Of course I'm assuming all the selected cells will share the same destination position. I can't wrap my head around noncontiguous sources to noncontiguous destinations in one drag-n-drop. If the user drags down 3 slots, does that mean you add 3 to the positions of all the selected cells? What if that takes a cell out of bounds? Even if you decided on some rules for odd cases like those and actually implemented this monstrosity, it could never be user friendly.

There is no easy way out. You need to handle the animation and movement by yourself.
Maybe you can take a copy of the cells you want to move and show an animation of moving to the destination.
When animation stops change the datasource.

Related

Swipe to delete on entire section in UITableView

I have a UITableView which has a variable amount of sections and every section has a variable amount of rows. Every section contains a section header, a section footer and the rows for that section. They are shown and displayed inside a container. Everything up until now works as expected. To demonstrate what my UITableView currently looks like:
I am now trying to implement the possibility to swipe left on the entire section, so that the header of the section, the rows inside this section and the footer of this section move to the left and display another UIView. I am capable of swiping the cells separately, but enabling this feature on the entire sections have caused headaches for the past two days. This is what I would like to achieve:
I have thought about implementing UIGestureRecognizers but I am afraid they might conflict with my UITableView. Also, I started implementing it, but I would not know how to move solely the section on which was swiped to the left.
Then I thought I could maybe implement a UIScrollView as container for each section. How I would accomplish this is still a mystery to me, but it seems like a possible solution if this could be done.
Furthermore I am out of ideas and stuck on how this should be done. It's something I have not found on the Internet so far - at least no working examples of some kind so I have zero inspiration on how to achieve the effect.
I therefor would like to ask if somebody has an idea of how this could work and what I have to keep in mind when implementing this. Every clue pointing me towards a working solution is gratefully appreciated!
EDIT: I have already seen the possible duplicate this afternoon. However, the suggestion there shows touchesBegan() on the header, which does not work in my case as I need the entire section to be "draggable".
I think one way you can implement this is with a vertical stackview containing views that contains a tableview and the trash icon. When a user swipes left on the tableview header, it will show the hidden trash icon in the view. I would think that each tableview only has one section so it will be easier to keep track of which "section" the user has swiped.
I have currently managed to arrange a similar solution. I take the rectangle of the section with rect(forSection:int), add a UIPanGestureRecognizer in which I add a UIView on top of the UITableView if touches began, I calculate the location of the finger and let the cudtom UIView follow. When a certain point (100 from left edge of the UITableView) is reached, the section gets removed with deleteSections(indexSet:with:).
This works. It does the job, but it adds an overlay to the section rather than pushing it to the left.
Therefor I am asking of someone knows if there is any way of setting the offset for one specific section or for an area of a UIView, so I can offset the rectangle of the section. I have been able to setContentOffset on the entire UITableView but this is not the desired result.
If there is no way to do this, I would consider keeping the solution I have now or maybe implement a snapshot feature which takes a screenshot and crops the rect of the frame, adding this UIImage to the custom view to simulate the section. But that would be tricky. Any ideas for this idea are also welcome.

Animate TableView Cell to swipe left

I would like to make a simple animation in the first cell of a table view to indicate that the user can delete this cell!
I have already completed the delete feature of the cell, etc.
How is it possible to achieve this like a bounce animation?
Facebook has already done that if you go to the notifications for the very first time you go to that view.
1) You can take one view inside cell. Design it whatever way you like.
2) Set it frames like it want be visible on screen while designing.
3) To adding animation effect, you can use default UIView animation or you can refer UIKit dynamics to achieve spring and bouns effect.
4) Set view frames progamatically to come from right to left.
4) Rest of the logic to display only one time, you can write it by yourselef :-)

Push apart TableViewCells while dragging over them. (Similar to UITableViewCellReorderControl)

I want to have a similar functionality like we have with the UITableViewCellReorderControl from the UITableViewCell, but as far as I know I cant use the reordercontrol.
I have implemented Drag & Drop for multiple UITableViews. I can Drag a cell from any TableView to any other. Drag & Drop does work so far. Now I want to push the cells apart when I'm dragging an object over 2 cells, just like Apple does this in Tableviews or when you reorder your apps (the place where you might drop gets empty to indicate the droplocation).
The solutions I thought about are:
1. Insert a placeholder image at the droplocation (this is not so good as I have to sync with CoreData all the time)
2. Change the height of the cell to simulate empty space below it.
I dont think that are the best solutions.

How make the same animation like UITableView reorder of cells?

I have a drag&drop operation between 2 UITableViews. The cell could be reordered in the source TableView, or move to another TableView.
Because I need to move the cell between the two, I can't use the default reorder support. However, I want to make a similar animation like when the cell is moving around and the cell below them slide out.
Any hint in how do this animation?
UPDATE:
You can see what exactly I'm looking for in the pulse app.
You can always use deleteRowsAtIndexPaths:withRowAnimation: to remove it from the source and insertRowsAtIndexPaths:withRowAnimation: to insert it into the destination.
if you want to do something similar to what makes "Pulse" you have to use "UIScrollView" for each row that you have and within the Views you need, if you do it UITableView is more complicated and would not be so easy to move between them

How move/reorder cells from TableView1 to TableView2

I have several UITableViews, with different datasources in a iPad screen.
I need to copy/move a cell from the first tableView to the second, similar how is done with ListBox in other languages.
Now, I can reorder the cells, but the movement is restricted to the tableView. I want to drag the cell in tableView1 & drop in tableView2.
P.D. I'm open to use any other control to archive this. I take a look at AQGridView & DTGridView, however the layout is based in columns with different #items. If I can emulate columns with this controls or other then I can accept the workaround.
UPDATE:
I hope this links could help:
Observing pinch multi-touch gestures in a UITableView
This is the most close answer:
Drag and drop between two tables in ipad
I know how get a image from a view, I can detect the drag with a Gesture Recognizers, so I have all the setup in place but have not expertise in graphic development, so don't know how put this in motion...
This is definitely a very interesting question, and I wish I had the time to put together some test code to see if the idea I'm about to outline would actually work. My hope is that this will at least point you in the right direction.
UITableViewCell is a subclass of UIView, so I would create a subclass of UITableViewCell called something like DraggableTableViewCell so we can handle the touch events and then perform the following steps:
Create an instance of DraggableTableViewCell and configure it to appear like the selected cell.
Add the new cell as a subview of a view that is a common superview to both tables at the same location as the original cell.
Update the data source for the source table view and remove the original cell from the table view using deleteRowsAtIndexPaths:withRowAnimation:
Move the cell on the display by responding to touchesMoved:withEvent:
When touchesEnded:withEvent: is received, verify the cell is somewhat close to the other table view and determine the index path where to insert the new cell
Update the data source for the destination table view and call insertRowsAtIndexPaths:withRowAnimation:
Remove your draggable cell from its superview with a nice animation.
This entire process will need to be orchestrated by the view controller that controls the various table views on the screen.

Resources