UICollectionViewFlowLayout item/line spacing only swapped with horizontal scrolling if all items are the same size

Originator:kelan
Number:rdar://19855783 Date Originated:2015-02-16
Status:Open Resolved:
Product:iOS Product Version:iOS 8.1
Classification: Reproducible:always
 
ummary:
I am using a UICollectionView with a standard FlowLayout, to show a single row of items.  I'm setting the scrollDirection to .Horizontal, and, according to the documentation, setting the minimumLineSpacing to 10.0, to give the horizontal padding between items.  But, that only works if all the cells are the same size.

Steps to Reproduce:
1. Set a UICollectionViewFlowLayouts properties to be:

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0.0;
    layout.minimumLineSpacing = 10.0;

2. Implement the -collectionView:layout:sizeForItemAtIndexPath: delegate method, and return dynamic item sizes (that are defined by external values for each item, so are potentially different for each cell).

3. Notice that sometimes the horizontal spacing between cells is 10.0, and sometimes it's 0.0.

4. In my case, the UICollectionView was just a single row (horizontally scrolling), but the StackOverflow post linked below shows the same for a 2D grid.

Expected Results:
The documentation for `UICollectionViewFlowLayout.minimumInteritemSpacing` says:

    For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column.

So, I was expecting that the interitemSpacing would be the horizontal spacing between the cells.  So, with the values specified above, there would be horizontal spacing between cells, but no vertical spacing.

Actual Results:
It seems like the interitemSpacing and lineSpacing are only "swapped" (as the documentation suggest) if all the cell are exactly the same size.  If the cells have different sizes, then the horizontal spacing is defined by the interitemSpacing.

Version:
iOS 8.1, using Xcode Version 6.1.1 (6A2008a)

Notes:
See these questions on StackOverflow (which, humorously/frustratingly, link to each other, and neither have answers).

http://stackoverflow.com/questions/26777942/serious-bug-for-uicollectionviewflowlayout-minimuminteritemspacing-and-minimuml

http://stackoverflow.com/questions/25571855/the-minimumlinespacing-property-of-the-uicollectionviewflowlayout-ios



Configuration:
iOS Simulator, Version 8.1 (550.3), using Hardware > Device: iPhone 6

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!