I have a UICollectionView that shows several rows with one, full-width column (looks like a UITableView)
What I'd like to achieve is something similar to this:
... where the middle cell has a much greater height. As the user scrolls up and down, the cells before and after the middle cell animate back to the default height for the given cell.
Can somebody outline how I should approach this problem?
I use this
Swift 3
code in my horizontalUICollectionView
.You need to create a custom subclass of
UICollectionViewLayout
.First of all, override
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
to return yes, that way, you can change the layout attributes of your cells as your collection is being scrolled.After that, your key methods to override are:
and
I suggest reading an article about custom collection view layouts. It can be pretty heavy subject matter.
since the
UICollectionView
is the subclass ofUIScrollView
, you can solved this problem by treating your collectionView as a scrollView.set the
UIScrollViewDelegate
and implementedscrollViewDidScroll
, and then do something like this:hope this will solve your problem.