I'm using the following to left align cells in a `UICollectionView`…

```
class LeftAlignedFlowLayout: UICollectionViewFlowLayout {
    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil }

        for attributes in attributes where attributes.representedElementCategory == .cell {
            attributes.frame = layoutAttributesForItem(at: attributes.indexPath).frame
        }
        return attributes
    }

    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes {
        let currentItemAttributes = super.layoutAttributesForItem(at: indexPath)!

        let layoutWidth = collectionView!.frame.width - sectionInset.left - sectionInset.right

        // Just left align the first item in a section
        if indexPath.item == 0 {
            currentItemAttributes.frame.origin.x = sectionInset.left
            return currentItemAttributes
        }

        let previousIndexPath = IndexPath(item: indexPath.item - 1, section: indexPath.section)
        let previousItemFrame = layoutAttributesForItem(at: previousIndexPath).frame

        let currentItemFrame = currentItemAttributes.frame
        let wholeRowFrameForCurrentItem = CGRect(x: sectionInset.left, y: currentItemFrame.minY, width: layoutWidth, height: currentItemFrame.height)

        // Left align the first item on a row
        if !previousItemFrame.intersects(wholeRowFrameForCurrentItem) {
            currentItemAttributes.frame.origin.x = sectionInset.left
            return currentItemAttributes
        }

        currentItemAttributes.frame.origin.x = previousItemFrame.maxX + minimumInteritemSpacing
        return currentItemAttributes, it's 
    }
}

```

Building for iOS 11 gives…

[![enter image description here](https://i.stack.imgur.com/Tyrn0.png)](https://i.stack.imgur.com/Tyrn0.png)

But for iOS 12 gives…

[![enter image description here](https://i.stack.imgur.com/aTkDi.png)](https://i.stack.imgur.com/aTkDi.png)

In iOS 11, `layoutAttributesForElements(in)` is called 3 times - the final time with the correct frame sizes. In iOS 12, it's only called twice, with frames being the estimated size.

Per this answer, <https://stackoverflow.com/a/52148520/123632> I've tried invalidating the flow layout using the `UICollectionView` subclass below (and "brute-forcing" in `viewDidAppear` of the containing view controller), but the result is unchanged.

```
class LeftAlignedCollectionView: UICollectionView {

    private var shouldInvalidateLayout = false

    override func layoutSubviews() {
        super.layoutSubviews()
        if shouldInvalidateLayout {
            collectionViewLayout.invalidateLayout()
            shouldInvalidateLayout = false
        }
    }

    override func reloadData() {
        shouldInvalidateLayout = true
        super.reloadData()
    }
}

```