Re: Can't get dynamically sized Collection View cells
Re: Can't get dynamically sized Collection View cells
- Subject: Re: Can't get dynamically sized Collection View cells
- From: Roland King <email@hidden>
- Date: Fri, 02 Oct 2015 21:14:08 +0800
> On 2 Oct 2015, at 20:30, Peter Tomaselli <email@hidden> wrote:
>
> [re-sending because my last message had size problems]
>
> Nifty way of demoing there, Roland, I’ll have to try that!
>
> I’d still be curious to know if anyone is using this feature “in production”. Because those crashes, problems rotating (at least for me), and also this, which I definitely ran into circa iOS 8:
>
> http://stackoverflow.com/questions/25573855/vertically-scrolling-uicollectionview-with-self-sizing-cells-only-displays-half <http://stackoverflow.com/questions/25573855/vertically-scrolling-uicollectionview-with-self-sizing-cells-only-displays-half>
>
> On Sep 30, 2015, at 9:34 PM, Roland King <email@hidden <mailto:email@hidden>> wrote:
>
>> [snip]
>>
>> Result, 150x150 boxes on the screen neatly laid out.
>>
>> Hooked up a button to iterate the cells on screen, find the embedded randomView and call its randomize function to reset the intrinsic content size, after they were all done, called collectionView.collectionViewLayout.invalidateLayout()
>>
>> Result, boxes all showed up in their new randomized sizes and the layout adjusted everything to fit, changed the number of boxes per line and the size of the lines. So just having cells with a fully-specified intrinsicContentSize and setting estimatedSize on the collection view flowlayout is enough to get dynamic cells without having to measure them or do any other work. So I deduce from that that Apple doesn’t lie and it does actually work as the WWDC session says.
>>
>> I did get some quite cool crashes when I set the estimated size far from the actual size, were I actually trying to do this for real I’d probably look into it but .. since I’m not.
Mine rotated fine, and scrolled fine, although the randomizing test I was doing just randomized visible cells because there weren’t any real underlying UIViews to deal with. I cranked it up to quite a bit of variation in the cell size without problems, but none of them were *radically* different sizes, they were probably 80-200 px in each direction, randomly. The cool crash I think I got when I set the estimated size too large, it ended up in an infinite loop somewhere trying to lay things out. I’d have to do quite a bit of work if I wanted to use that for real to convince myself I knew what prompted it.
I wondered at the time also whether it was really necessary to call invalidateLayout() but of course it is. Things like stackview are constraints all the way down, everything is constrained and when anything changes, the layout recalcuates automatically. Collection views are a 2-pass operation, work out a size and position for everything, then set it, so the ‘constraints’ if you look at it like that are just fixed positions.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden