Closed jonathantrevor closed 10 years ago
A current workaround is to say you have 1 or 2 more items than you actually have and return fake cells and sizes for them. But that isnt ideal.
The behavior of the layout mechanism is that it always tries to fill the available space. The issue with implementing a maximumRowHeight is that it would break the layout mechanism's ability to do that.
Can you explain the kind of behavior that you would expect? Is this only an issue when displaying one or two items?
Im trying to lay out a number of items, between 1 and 100. I'd like them to NOT be constrained by the frame they are in (Im adding them to a parent scroll view) but for each row to roughly be around 100px (for example). So I create the collection view in a really tall frame first, layout the contents, and then resize to fit the height. This strategy works really when I have 3 or more but if I have less than 3 OR all of the images are really tall (say 1000px) then I dont get any reduction in height since the layout manager CAN layout the items and "fit" them in the row. So its not only an issue with fewer than 3 items - but thats the easiest to see it happening on.
So Im currently adding in fake small cells to force the row closer to the minmum height I specify. I guess I could also try and limit the height and do some kind of average guess of the height I'll need for, say 3, items per row.
Thanks for the quick response.
Thanks for the explanation. I'm not sure that this component offers the functionality that you're looking for. You might want to try and write your own custom collection view layout. This article offers a good starting point: http://www.objc.io/issue-3/collection-view-layouts.html
I'd like to see a maximum cell size, too. Of course this would mean that the requirement of always filling the row horizontally can't be fulfilled anymore. Nevertheless this would help in the standard case of of a single picture that's zoomed up to 100% row width.
If I try and layout one or two items I cannot seem to restrict the height. For example, if the image is really tall (say 1000px and only 10px wide) and I return a scaled estimated item size of 100px the layout manager still lays it out at 1000px.
Is there any way of preventing this problem? For example by providing a maximumRowHeight or perhaps have the estimated size layout closer to what Im returning?