CollectionView V205 (2012) V219 (2012) V232 (2014)


Screen Shot 2014-07-22 at 12.30.52


Screen Shot 2014-07-22 at 12.08.55


UICollectionViewLayoutAttributes (some)
– Position
– Size
– Opacity
– zIndex
– Transform
– …

Customization of Layout
– Size
– line spacing
– Inter cell spacing
– Scrolling direction
– Header Footer size
– Section inset

– Want single line -> play with insets

Supplementary views are data driven
Decoration views are layout driven -> independent from the data e.g: Background

Carries information from a Layout to a Collection view and gets supplied to all the views in the collection view. One instance per view. Attributes: center, size, frame, alpha, transform, zIndex (to indicate how cells are stacked on top of each other)

Layout that get information from the CollectionViewDelegate

– When a change is done in a layout, the layout gets invalidate via -invalidateLayout
– If you want to change a a property on the layout but you want it to be done with animation performBatchUpdates:completion: to begin updates and end updates on a TableView (CollectionView). E.g: Item size on the layout
– CoverFlow we want to change transforms the view which means changing layout attributes, respond to method shouldInvalidateForBoundsChange: Flowlayout implements this method on the rotation of the device

When implementing a CollectionView with custom Layout, think first if it can be solved by sublcassing UICollectinViewFlowLayout

– Customise and add new kinds of views (decoration view, etc)
– Tweak layout attributes: To transform, alpha, etc.
– Add new layout attributes. Subclassing UICollectionViewLayoutAttributes to add additional layout attributes. E.g: to adjust some visual property on the cell to depend on the column.
– Gesture support, gesture to a specific cell.
– Custom insert and delete animations

Fully customizing UICollectionViewLayout
UICollectionViewLayout is an abstract class that needs to be extended in order to create a custom layout

Required overrides
- collectionViewContentSize
tells the user scrollable area in the collection view, where the content is going to be layout
- layoutAttributesForElementsInRect:
called to ask how to lay things out returns an array of LayoutAttributes
- layoutAttributesForItemAtIndexPath:
Additionally sometimes this is required as well.
- layoutAttributesForSupplementaryViewOfKind:atIndexPath:
- layoutAttributesForDecorationViewOfKind:atIndexPath:

Order of operation to call those methods
– prepareLayout
to do upfront calcs for layout e.g: circle layout, etc.
– others
invalidateLayout (like in coverflow, when sizes need to change. Says to collection view to start over again)
– cycle continues

Leave a Reply

Your email address will not be published. Required fields are marked *