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

Commit 6c91863

Browse files
author
周昌鸿
committed
avoid update currentPage when setCurrentPage
1 parent 5f054c4 commit 6c91863

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Lib/CollectionViewPagingLayout.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
6565

6666

6767
// MARK: UICollectionViewLayout
68-
var ignoreBoundsChange : Bool = false
68+
var ignoreUpdateCurrentPage : Bool = false
6969

7070
override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
71-
!ignoreBoundsChange
71+
true
7272
}
7373

7474
override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
@@ -130,7 +130,9 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
130130

131131
override public func invalidateLayout() {
132132
super.invalidateLayout()
133-
updateCurrentPageIfNeeded()
133+
if !ignoreUpdateCurrentPage{
134+
updateCurrentPageIfNeeded()
135+
}
134136
}
135137

136138

@@ -175,10 +177,10 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
175177
offset = max(0, offset)
176178
offset = min(offset, maxPossibleOffset)
177179
let contentOffset: CGPoint = scrollDirection == .horizontal ? CGPoint(x: offset, y: 0) : CGPoint(x: 0, y: offset)
178-
ignoreBoundsChange = true
180+
ignoreUpdateCurrentPage = true
179181
CATransaction.begin()
180182
CATransaction.setCompletionBlock({
181-
self.ignoreBoundsChange = false
183+
self.ignoreUpdateCurrentPage = false
182184
self.updateCurrentPageIfNeeded(basedOn: contentOffset)
183185
})
184186
CATransaction.commit()

0 commit comments

Comments
 (0)