UITableView: Drag'n'drop making space between cells - ios

How would I make the cells, below the one that I drag, go down, making a space for insertion?
Example.
I expect it to behave like following:

This is a pretty good implementation. Basically you have a a gesture recognizer to do a tap and hold and then pan around (the trick begin that you dont move the cell on the pan, you move a UIImageView with a snapshot of the cell)
As the cell moves, you detect which row is beneath, and move the table view's cells accordingly (e.g. with moveRowAtIndexPath:toIndexPath:)

Related

Pan gesture in UITableViewCell that can move image view all over tableview without going beneath the cell

I am trying to create a tinder like swipe left and right in UITableView cell. Here, the tableview cell contains an image view which I can move around with pan gesture. When I initiate the gesture on the image view, I want to move it freely over my device screen.
I am facing the problem that when I move the image view around it goes below the current cell. How can I bring the image view over all others so it doesn't go below the cell frame?
I tried using view.bringSubviewToFront but it doesn't work.
Please suggest a way I can achieve this.
An image view still contained in a cell is not going to be reliably brought on top of all other relevant views. You will have to move that view from the cell to the table view's parent view while dragging (and then return it to the cell if necessary at the end).
You will probably want to look into UIView.convert(_:from:) to figure out the frame to move the image view to in the parent view.

UICollectionView Cells do not animate movement

When I initiate movement for my collectionView cells, the cells do not move. They move only when I pan my finger over another cell. So if I initiate a movement by pressing one of my cells and then pan, the cells do not track my finger. The only time animation occurs is when my finger pans over another cell. At that point the animation is just the reordering. Bonus: One I end my gesture (lift up my finger) the current cell I was moving around disappears from view. I am using a custom flow layout
My custom flowLayout is stopping the animation. In my custom layout I set the frames of my cells (their attribute frames) to a specific position that is hardcoded in my layout. When the long press gesture is initiated I have to change my attributes somehow.
You don't need to update your attributes. Just make sure you are overriding these methods in your custom layout:
layoutAttributesForElements
layoutAttributesForItem
layoutAttributesForSupplementaryView

Unable to grab UITableViewCell to move it (reorder) because of subView

I was being able to move my tableViewCells just fine until I added a UIView as subView of my UITableViewCell. The width of this subView is the same of my cell. This means it covers it completely. This subView is in fact transparent enough for the grabber control to be seen even though it is over it.
I understand I am not being able to move the cells to reorder them because the view that I put over my tableViewCell is covering it completely and is over the grabber control and is not letting the grabber control detect the pan gesture.
Is it possible somehow for my views to detect this pan gesture and pass it on to the grabber control so that I can reorder the cells?
If not, is it possible to do this cell moving and reorder manually? (Having my own cell grabber control over my tableView).
Some objective C snippet will be much appreciated.

UIRefreshControl (pull to do something) on every cell

How do i apply UIRefreshControl(or something similar) on every cell of a UICollectionView.
I need to invoke an event when cell is swiped to left side and released(if not released but swiped back to its original position, then take no action).
Apple uses UIScrollView extensively for this kind of thing.
Add a (horizontally scrolling) UIScrollView to the cell. Then make the cell the delegate of it.
Now you can pick up whenever it is scrolled and do something if it scrolls past a certain point.

UITableViewCell horizontal custom swip- to-delete effect

I have a UITableView and would like to have a custom way to delete my cells. When someone swipe on it, the cell would move horizontally on the side and disappear.
Exactly like the multitasking menu on iOS 7 (http://movies.apple.com/media/us/ios/ios7/f34c5445-5a9c-4b3a-9556-8efe89147559/shared_multitasking/shared_multitasking_2x.mp4), but instead of swiping vertically, it would be horizontal.
Does any one knows how to do that? Should I just detect a swipe and change the frame of my cell with a 1 sec animation? Or are there nice subclasses of UITableViewCell you would recommend?
I just threw together a very basic example of how to do this and posted it here: https://github.com/NSPostWhenIdle/MMSwipeToDeleteCollection. Don't expect to be able to drag and drop this into your project and have it work, because quite frankly it probably won't.
The basic idea to create something like this starts with a subclass of UICollectionViewCell that adds a gesture to the cell. In my example, I used a swipe gesture because I'm lazy :p and there is more overhead involved in setting up a pan gesture (which you'll want in your end product) because there is conflict between that pan gesture, and the pan gesture in the collection view's scroll view.
From there it's basically smooth sailing. When the gesture recognizer gets called you animate the cell out the top of the screen. If you set this up with a pan gesture, you'll need to configure this to drag the cell, and animate up or down upon completion, but in my swiping example, the cell moves to just out the top (of the 4 inch simulator, I used static values).
Then all that's left to do is some clean up. Once the cell has exited the screen you can safely delete it from your datasource and then from the collection view. (I used notification center do alert the collection view, but you should probably make a protocol) The only issue I had with this was that the cell animated back down while fading out as part of the stock deletion animation. Setting its alpha to 0 after it leaves the screen solves this problem.

Resources