> On 1 Oct 2015, at 07:57, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> There are few pieces of evidence that lead me to believe you that this hasn’t 
> been done:
> 
> • A search of ADC site doesn’t show any sample code with this technique.
> • A Google search turns up almost nothing, except the link I provided below.
> • A search of all github and bitbucket public turns up no references to 
> estimatedItemSize.
> 
> The funny thing is that I’ve implemented a dynamically sized table view cell 
> using the techniques described in the WWDC presentation, and it works great. 
> But there’s something about doing this with collection views that doesn’t 
> quite work.
> 
> So, does Apple lie?
> 
> Thanks.
> 
> Doug Hill


Nope - you actually made me go and test it. Made a little UIView which has an 
intrinsic content size and can randomize that, and set 
invalidateIntrinsicContentSize() when it does). Put a UICollectionView in the 
storyboard and set up the one cell to have one of those views in it, pinned to 
all sides. Set up the datasource to make 1 section, 100 such cells and dequeued 
one cell for each. Started them all off at 150x150. 

Set collectionView.collectionViewLayout.estimatedSize to 100x100. 

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. 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to