diff --git a/Persephone/Controllers/AlbumViewController.swift b/Persephone/Controllers/AlbumViewController.swift index 5f5ca5b..e4bf9b1 100644 --- a/Persephone/Controllers/AlbumViewController.swift +++ b/Persephone/Controllers/AlbumViewController.swift @@ -46,6 +46,10 @@ class AlbumViewController: NSViewController, override func viewWillLayout() { super.viewWillLayout() + if let layout = albumCollectionView.collectionViewLayout as? AlbumViewLayout { + layout.saveScrollPosition() + } + albumCollectionView.collectionViewLayout?.invalidateLayout() } diff --git a/Persephone/Layouts/AlbumViewLayout.swift b/Persephone/Layouts/AlbumViewLayout.swift index 5a93b65..2bf5bf1 100644 --- a/Persephone/Layouts/AlbumViewLayout.swift +++ b/Persephone/Layouts/AlbumViewLayout.swift @@ -36,10 +36,6 @@ class AlbumViewLayout: NSCollectionViewFlowLayout { var divider: CGFloat = 1 var itemWidth: CGFloat = 0 - if let scrollView = collectionView.enclosingScrollView { - scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height - } - repeat { let totalPaddingWidth = sectionInset.left + sectionInset.right let totalGutterWidth = (divider - 1) * (minimumInteritemSpacing) @@ -52,6 +48,15 @@ class AlbumViewLayout: NSCollectionViewFlowLayout { itemSize = NSSize(width: itemWidth, height: itemHeight) } + func saveScrollPosition() { + guard let collectionView = collectionView + else { return } + + if let scrollView = collectionView.enclosingScrollView { + scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height + } + } + func setScrollPosition() { guard let collectionView = collectionView else { return }