drix drix - 1 month ago 25
iOS Question

UIKit Dynamics on a UITableView

Can you add the springy cells effect when scrolling (like in the Messages app on iOS7) to an

? I've seen examples of it working on an
, 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?


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.