NSCollectionView custom layout enable scrolling
<p>I can't get scrolling both vertically and horizontally to work with a custom layout for <code>NSCollectionView</code>.
According to the docs, in my subclass I return the <code>collectionViewContentSize</code> and if that is too big, scrolling is automatically enabled in the enclosing scroll view of the collection view. However, even if I order all elements in a horizontal row, only vertical scrolling is enabled.</p>

<p>Here is a screenshot:
<a href="https://i.stack.imgur.com/tMbCN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tMbCN.png" alt="Screenshot"></a></p>

<p>Here is my layout code:</p>

<pre><code>class Layout: NSCollectionViewLayout
{
var cellSize = CGSize(width: 100, height: 30)

var cellSpacing: CGFloat = 10
var sectionSpacing: CGFloat = 20

private var contentSize = CGSize.zero
private var layoutAttributes = [NSIndexPath: NSCollectionViewLayoutAttributes]()


override func prepareLayout() {
    guard let collectionView = collectionView else { return }

    let sections = collectionView.numberOfSections
    guard sections &gt; 0 else { return }

    contentSize.height = cellSize.height

    for section in 0..&lt;sections {
        let items = collectionView.numberOfItemsInSection(section)
        guard items &gt; 0 else { break }

        for item in 0..&lt;items {
            let origin = CGPoint(x: contentSize.width, y: 0)
            let indexPath = NSIndexPath(forItem: item, inSection: section)
            let attributes = NSCollectionViewLayoutAttributes(forItemWithIndexPath: indexPath)
            attributes.frame = CGRect(origin: origin, size: cellSize)
            layoutAttributes[indexPath] = attributes

            contentSize.width += cellSize.width + cellSpacing
        }
        contentSize.width += sectionSpacing
    }
}

override var collectionViewContentSize: NSSize {
    return contentSize
}

override func layoutAttributesForElementsInRect(rect: NSRect) -&gt; [NSCollectionViewLayoutAttributes] {

    return layoutAttributes.values.filter { $0.frame.intersects(rect) }
}

override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -&gt; NSCollectionViewLayoutAttributes? {
    return layoutAttributes[indexPath]
}

override func shouldInvalidateLayoutForBoundsChange(newBounds: NSRect) -&gt; Bool {
    return false
}
}
</code></pre>