Re: Dynamic-width Collection View
Re: Dynamic-width Collection View
- Subject: Re: Dynamic-width Collection View
- From: Doug Hill <email@hidden>
- Date: Wed, 10 Aug 2016 15:41:53 -0700
On Aug 10, 2016, at 3:18 PM, Jonathan Hull <email@hidden> wrote:
>
> The main issue is that the cell doesn’t (and shouldn’t) have any idea about what size the collectionView is. You could actually use the delegate though (which has a wider view) and provide the size that way.
Agreed that the cell shouldn't know about the collection view width. But given that Apple says that the size needs to be calculated in the cell's override of preferredLayoutAttributesFittingAttributes for self-sizing cells, I'm stuck with it.
> That said, I did additional research and found other people with your issue. Relevant posts:
> https://github.com/imyoungyang/DynamicHeight <https://github.com/imyoungyang/DynamicHeight>
> http://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout <http://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout>
As with everything else I've read about this topic, these links have numerous comments of the form "Self-sizing cells is horribly broken. Maybe my hack will work but I'm not sure."
<RANT>The entire iOS developer community would like this to be fixed by Apple. Both documentation and bugs.</RANT>
> My recommendation would be to remove the preferredAttributes stuff, and give your cell’s content view an explicit width constraint. Then in the collectionView:layout:sizeForItemAtIndexPath: method of your FlowLayoutDelegate, set the constant of the width constraint to the desired width (you are passed the collectionView). Then return the result of contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize). Note: I haven’t actually tried this… all code written in mail.
I actually started working on this, and will report if it gets me any further.
Appreciate the feedback.
Doug Hill
> Thanks,
> Jon
>
>> On Aug 10, 2016, at 2:27 PM, Doug Hill <email@hidden <mailto:email@hidden>> wrote:
>>
>> Jonathon,
>>
>> Thanks for the feedback.
>>
>> A question that comes to mind is, what about making cells the same size as the collection view requires going through subclassing the collection view layout? Apple documentation IMPLIES this should work. It even documents that developers should use preferredLayoutAttributesFittingAttributes for this very purpose.
>>
>> The reason I don't want to subclass flow layout is that I pretty much want the exact functionality the default flow layout provides:
>>
>> 1. Automatically calculating layout rects that flow across lines.
>> 2. Calculating the height of cells dynamically at runtime via 'estimatedItemSize'
>>
>> Given that, I'm open to ideas on what I should override in a layout subclass. Particularly ones that don't require me to reimplement #1 and #2 above.
>>
>> Doug Hill
>>
>>> On Aug 10, 2016, at 2:16 PM, Jonathan Hull <email@hidden <mailto:email@hidden>> wrote:
>>>
>>> Because you are trying to make the width of the cell the same size as the collection view, I would strongly consider writing a small subclass of flow layout. It honestly sounds like less work than what you are dealing with now.
>>>
>>> Thanks,
>>> Jon
>>>
>>>> On Aug 10, 2016, at 1:29 PM, Doug Hill <email@hidden <mailto:email@hidden>> wrote:
>>>>
>>>>>
>>>>> On Aug 10, 2016, at 11:10 AM, Doug Hill <email@hidden <mailto:email@hidden>> wrote:
>>>>>
>>>>> I'm currently trying to implement something that seems basic but has been driving me nuts: making a Collection View with cells that are dynamic-width and height at runtime.
>>>>>
>>>>
>>>> Again, looking for any ideas, pointers, etc. about any of this, including whether I'm going about this the wrong way.
>>>>
>>>> Doug Hill
>>
>
_______________________________________________
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