UICollectionViewFlowLayout layout not correct on iPad Pro 10.5”

Originator:addison.f.webb
Number:rdar://42798866 Date Originated:07-31-2018
Status: Resolved:
Product:iOS + SDK Product Version:11
Classification:Bug Reproducible:Always
 
I am trying to center the cells of a collection view. My strategy to do this was to provide a delegate to the `UICollectionView` that conformed to `UICollectionViewDelegateFlowLayout` and implement the `collectionView:layout:insetForSectionAtIndex` method to return an inset to center the content. **See `ProductsCollectionViewDelegate` in the sample project.**

I believe this strategy should work. It seems to work on every device in every orientation except for **portrait orientation** on the 10.5” iPad Pro. For some reason the inset seems to be calculated correctly but the collection view is rendered with 1 cell too few in each row.

I added logging statements to see the calculations. It appears as if the calculations are correct.

```
*-------------------- begin calculating inset -------------------------*
*Screen width: 834.0*
*View width: 834.0*
*Number of cells that will fit in a row: 4.0*
*Final number of cells in row: 4.0*
*Total cell width: 800.0*
*Total space width: 24.0*
*Inset: 5.0*
*total cell width + total space width + 2(inset) = total view width*
*800.0 + 24.0 + 10.0 = 834.0*
*834.0 = 834.0*
*-------------------- end calculating inset -------------------------*
```

Steps to Reproduce:
To see attached sample project.

Run the project on the iPad 10.5” simulator. Verify the content is not evenly spaced or centered in portrait. Flip to landscape to see an example of what the correct layout should look like. 

You can also run the sample project on any other device simulator and the collection view should render correctly in each orientation.

Expected Results:
In portrait orientation, there should be 4 items in a row. The items in rows should be separated by 8 points and centered.

Actual Results:
Only 3 items are in a row and they are unevenly spaced and not centered.

** See sample here:
https://github.com/addisonwebb/BrickAndMortar

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!