@@ -135,15 +135,16 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
135
135
136
136
// MARK: Private functions
137
137
138
- private func updateCurrentPageIfNeeded( ) {
138
+ private func updateCurrentPageIfNeeded( basedOn contentOffset : CGPoint ? = nil ) {
139
139
var currentPage : Int = 0
140
140
if let collectionView = collectionView {
141
+ let contentOffset = contentOffset ?? collectionView. contentOffset
141
142
let pageSize = scrollDirection == . horizontal ? collectionView. frame. width : collectionView. frame. height
142
- let contentOffset = scrollDirection == . horizontal ?
143
- ( collectionView . contentOffset. x + collectionView. contentInset. left) :
144
- ( collectionView . contentOffset. y + collectionView. contentInset. top)
143
+ let offset = scrollDirection == . horizontal ?
144
+ ( contentOffset. x + collectionView. contentInset. left) :
145
+ ( contentOffset. y + collectionView. contentInset. top)
145
146
if pageSize > 0 {
146
- currentPage = Int ( round ( contentOffset / pageSize) )
147
+ currentPage = Int ( round ( offset / pageSize) )
147
148
}
148
149
}
149
150
if currentPage != self . currentPage {
@@ -174,5 +175,6 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
174
175
offset = min ( offset, maxPossibleOffset)
175
176
let contentOffset : CGPoint = scrollDirection == . horizontal ? CGPoint ( x: offset, y: 0 ) : CGPoint ( x: 0 , y: offset)
176
177
collectionView? . setContentOffset ( contentOffset, animated: animated)
178
+ updateCurrentPageIfNeeded ( basedOn: contentOffset)
177
179
}
178
180
}
0 commit comments