Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit 4c52be1

Browse files
author
grant
committed
Merge branch 'grant.zhou/github_multisections' into 'master'
ignore bounds change when setCurrentPage See merge request grant/CollectionViewPagingLayout!3
2 parents 009cd9a + 073f3ce commit 4c52be1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Lib/CollectionViewPagingLayout.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
6565

6666

6767
// MARK: UICollectionViewLayout
68+
var ignoreBoundsChange : Bool = false
6869

6970
override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
70-
true
71+
!ignoreBoundsChange
7172
}
7273

7374
override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
@@ -174,7 +175,9 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
174175
offset = max(0, offset)
175176
offset = min(offset, maxPossibleOffset)
176177
let contentOffset: CGPoint = scrollDirection == .horizontal ? CGPoint(x: offset, y: 0) : CGPoint(x: 0, y: offset)
178+
ignoreBoundsChange = true
177179
collectionView?.setContentOffset(contentOffset, animated: animated)
180+
ignoreBoundsChange = false
178181
updateCurrentPageIfNeeded(basedOn: contentOffset)
179182
}
180183
}

0 commit comments

Comments
 (0)