How to create collection view that scrolls both ways?

Hi,


I'm trying to do something which I think ought to be pretty simple. I want to have a collection view that is a regular N x N grid, and I want each cell in the grid to be a fixed size, allowing the grid to scroll in either direction if necessary.


I have used UICollectionView before, so I know how to set up a data source and a cell, and I know how to implement sizeForItemAtIndexPath to specify the size I want for my cells.


It would appear that the default flow layout can only support scrolling in one direction at a time, which I guess makes sense, so I decided to create my own layout.


Now I'm stuck looking at methods like layoutAttributesForItemAtIndexPath and layoutAttributesForElementsInRect that I have to implement in my layout class. I am not sure what to do here. I don't know what a "layout attribute" is, and I'm confused/surprised/annoyed that I apparently am being asked to calculate on my own which cells appear in a given rectangle of the view.


Is there some easier way to accomplish this?

Hi,


If there isn't a class somewhere at the web, which does exactly what you need, you have to implement it on your own. I've created a collectionViewLayout with a fixed column with and a variable item height. And yes, you have to do all the calculations yourself. But for a grid-style layout this should by quite easy to implement. I suggest reading some docs but the most important part of a UICollectionViewLayoutAttributes object is the frame, which tells the collection view where to put the collection view items at.


Dirk

How to create collection view that scrolls both ways?
 
 
Q