Custom UICollectionView Layout-entry, uicollectionview Layout
Custom UICollectionView Layout-entry 0. application scenarios:
Various cells are often used in projects. Sometimes custom cells cannot meet product requirements. We can choose a complicated and difficult development method to solve the problem, of course, you can also choose a simple but skillful solution. The custom UICollectionView layout is a good way. This section describes how to use the custom UICollectionView layout to create a beautiful interface.
1. Inheritance plan
- 1> inherit from UICollectionViewLayout
- 2> inherit from UICollectionViewFlowLayout
2. methods that may need to be rewritten
1> prepareLayout
- Set some initialization parameters here to perform initialization.
- You must call [super prepareLayout];
2> layoutAttributesForElementsInRect:
- The returned array contains the UICollectionViewLayoutAttributes object.
- Return the layout attribute of all elements (such as cell) in collectionView: This method determines how the cell is arranged.
- Each cell has its own layout attribute: UICollectionViewLayoutAttributes
3> shouldInvalidateLayoutForBoundsChange:
- Whether to refresh the layout when the bounds of the uicollectionView changes
- Once you refresh the layout, the methods 1> and 2> are called in sequence.
4> targetContentOffsetForProposedContentOffset: withScrollingVelocity:
- The returned value of this method determines the final offset of collectionView (the final position)
- ProposedContentOffset parameter: the offset of collectionView.
- Velocity parameter: Rolling rate of collectionView
5> layoutAttributesForItemAtIndexPath:
- If you inherit UICollectionViewLayout, you 'd better implement this method.
- Purpose: return the layout attribute of the cell in the indexPath position.
PS: code will be uploaded later.