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

Commit 5f054c4

Browse files
author
grant
committed
Merge branch 'grant.zhou/github_multisections' into 'master'
避免触发回调错误的问题 See merge request grant/CollectionViewPagingLayout!5
2 parents 6a472c6 + 96aea43 commit 5f054c4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Lib/CollectionViewPagingLayout.swift

Lines changed: 10 additions & 2 deletions
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,14 @@ 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
179+
CATransaction.begin()
180+
CATransaction.setCompletionBlock({
181+
self.ignoreBoundsChange = false
182+
self.updateCurrentPageIfNeeded(basedOn: contentOffset)
183+
})
184+
CATransaction.commit()
177185
collectionView?.setContentOffset(contentOffset, animated: animated)
178-
//updateCurrentPageIfNeeded(basedOn: contentOffset)
186+
179187
}
180188
}

0 commit comments

Comments
 (0)