Skip to content

Example of issues with drag-to-reorder in a UICollectionView with self-sizing cells

Notifications You must be signed in to change notification settings

tomhamming/collection_view_auto_size_reorder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Reordering in UICollectionView with self-sizing cells

UICollectionView has awesome drag-to-reorder support. But if you use self-sizing cells, at least as of iOS 11, during a drag operation it reverts all cells to its estimated cell size (defaults to 50 x 50). This is no fun.

This repo started out as an illustration of the issue. Then I found a way around it:

  • Keep one instance of your cell class around as a sizing cell
  • Configure it with your data, then ask it for its preferred size (systemLayoutFittingSize)
  • Return this size from sizeForItemAtIndexPath
  • Cache this information in a dictionary of NSIndexPath to NSValue so you don't have to continuously recalculate sizes (which gets expensive on non-trivial layouts).

About

Example of issues with drag-to-reorder in a UICollectionView with self-sizing cells

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published