UIRefreshControl (pull to do something) on every cell - ios

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.

Related

UITableView scroll at top issue iOS

I have a tableview and I would like to know when user scroll at top and if in those moment the tableview is not at top (for example its at middle) I just implement the delegate method scrollViewDidScroll and check the value of content offset and its ok.
My problem is when the tableview is is already at the top and scrollViewDidScroll is not called (I want to know if the user do the gesture for scroll to the top even if it is already at the top).
For this reason I thought to add a pan gesture to tableview but I saw that create problems about scrolling and the implementation is cumbersome.
I ask to you if you know another way to achieve this or the only way is adding pan gesture.
You should try to use scrollViewWillBeginDragging or scrollViewWillEndDragging

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

Adding a Scrolling Subview to a UITableView (NOT a Cell)

I'm creating my views programmatically. I have a UITableView in my UIViewController subclass that I want to add a scrolling subview to that is not a cell. I want to add some text-based subview to the UITableView that scrolls with the table and starts out above y=0 so the user will only see it if he pushes the table down. That is, it should reside above the first section of my table. If it helps for visualization, I intend to make something similar to those "scroll down to refresh" features and want some indication to the user that scrolling down causes a refresh. Is there any way to do this without something messy like using another UITableViewCell to represent it or abusing the UITableView delegate methods to move a view around whenever the user scrolls?
Simply using [tableView addSubview:] in my viewWillLoad only makes it appear for a split-second then disappear once the table data is loaded. This seems weird to me because UITableView is a subclass of UIScrollView, which is meant to hold other views in it. Using [tableView.backgroundView addSubview] does nothing.
P.S. Why not use a UIRefreshControl for this? I'm still undecided but leaning towards not using one because I don't like how slow that spinning wheel "feels" when the refreshes are usually very very quick. I've been looking at other options like flashing the background subtly and only showing a wheel if it's taking a longer time than usual.
I You can implement pull to refresh with only a table view
To do this using the scroll view delegate, since tableview is a subclass of scroll view.
Set view controller to be the tableview delegate and implement
(void)scrollViewDidScroll:(UIScrollView *)scrollView
When scrollview content offset y value passed a point, add a label to the viewcontroller.view not tableview. When you scroll back or release, remove the view.
You might also be able to add label to the table view and set the frame origin to negative y value, so when you pull the label will move into view (Never tested this do might not work)

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.

UITableView: Drag'n'drop making space between cells

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:)

Resources