Q:

Get indexPathsForVisibleItems() not including ones under a translucent navigation bar

I am developing an app targeting iOS 8.0+ using Swift 2.2. I have a UICollectionView which displays a different number of columns depending on the device orientation. In viewWillTransitionToSize, I use indexPathsForVisibleItems() and find the smallest index path to determine the first visible item and scroll to that item on orientation change.
This works well except that indexPathsForVisibleItems() includes items which are under the translucent navigation bar so the scrolling may be off by a few cells. Is there some way to know which cells are visible and not under the navigation bar?

A:

If you want to scroll to a specific cell on rotation you could get the physical location of that cell on screen (take the height of your translucent navigation bar and the y coordinate of the cell) and call indexPathForItemAtPoint.  That will give you the first cell that is actually visible (not under the overlay).  Then you can tell the UICollectionView to scroll to that cell on rotation.

