UIKit Dynamics on a UITableView

6.1k Views Asked by At

Can you add the springy cells effect when scrolling (like in the Messages app on iOS7) to an UITableView? I've seen examples of it working on an UICollectionView, but absolutely nothing for table views.

Is it just not possible and I should change every table view to a collection view and redo all the cells?

2

There are 2 best solutions below

0
On BEST ANSWER

Unfortunately, no.

Every UICollectionView has a layout object (a UICollectionViewLayout subclass) that describes where each cell should go in the collection view's scroll view and which cells are visible in a given CGRect. UITableView doesn't have this, so it would be much harder to do anything that manipulates the position of its cells.

In addition to animating UIView objects, UIKit Dynamics can be used to animate UICollectionViewLayoutAttributes directly, which is necessary for a UITableView or UICollectionView style class that has reusable cells that may not all be on screen, but which would still be part of the UIDynamicAnimator's "physics". UIDynamicAnimator methods such as layoutAttributesForCellAtIndexPath: can then be used to populate your layout object.

There being no equivalent layout object for a UITableView, and no equivalent UIDynamicAnimator code to operate on off-screen UITableView cells, it's likely to be much easier for you to switch to a UICollectionView if you want this behaviour.

0
On

In the WWDC 2013 session Exploring Scroll Views in iOS 7 they talk about doing this effect with a collection view and UIKit Dynamics. I'd imagine that it's much easier to do it with a collection view than a table view since it's easier to position the cells. There may be sample code to go along with the session.