Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIKit Dynamics on a UITableView

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?

like image 309
drix Avatar asked Dec 30 '13 14:12

drix


Video Answer


1 Answers

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.

like image 181
knellr Avatar answered Oct 05 '22 08:10

knellr