A UICollectionViewFlowLayout subclass that supports CSS sticky style.
You could pin everything(item/header/footer) to the edge of the collectionView with a specific distance.
Just use it like the UICollectionViewFlowLayout
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: StickyCollectionViewFlowLayout())
collectionView.delegate = self
- Ask you about the specific distance you want to pin the cell with. Return nil if not a sticky element.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, stickyDistanceAt indexPath: IndexPath) -> CGFloat?
- Asks you about the specific distance you want to pin the header with. Return nil if not a sticky element.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, stickyDistanceForHeaderInSection section: Int) -> CGFloat?
- Ask you about the specific distance you want to pin the footer with. Return nil if not a sticky element.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, stickyDistanceForFooterInSection section: Int) -> CGFloat?
- Notify you that the current edge insets made by the sticky elements, which could be used to update the scroll indicator insets.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, stickyInsetsDidChange stickyInsets: UIEdgeInsets)