This repository was archived by the owner on Jun 17, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,13 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
43
43
}
44
44
45
45
private var numberOfItems : Int {
46
- collectionView? . numberOfItems ( inSection: 0 ) ?? 0
46
+ var count = 0 ;
47
+ if let sectionCount = collectionView? . numberOfSections {
48
+ for i in ( 0 ..< sectionCount) {
49
+ count += collectionView? . numberOfItems ( inSection: i) ?? 0
50
+ }
51
+ }
52
+ return count
47
53
}
48
54
49
55
@@ -88,8 +94,23 @@ public class CollectionViewPagingLayout: UICollectionViewLayout {
88
94
let endIndex = min ( numberOfItems, initialEndIndex + startIndexOutOfBounds)
89
95
90
96
var attributesArray : [ UICollectionViewLayoutAttributes ] = [ ]
97
+ let sectionCount = collectionView? . numberOfSections ?? 0
91
98
for index in startIndex..< endIndex {
92
- let cellAttributes = UICollectionViewLayoutAttributes ( forCellWith: IndexPath ( row: index, section: 0 ) )
99
+ var section = 0
100
+ var row = 0
101
+ var accIndex = 0
102
+ for i in ( 0 ..< sectionCount) {
103
+ if index - accIndex < collectionView!. numberOfItems ( inSection: i) {
104
+ section = i
105
+ row = index - accIndex
106
+ break ;
107
+ }
108
+ else {
109
+ accIndex += collectionView!. numberOfItems ( inSection: i)
110
+ }
111
+ }
112
+
113
+ let cellAttributes = UICollectionViewLayoutAttributes ( forCellWith: IndexPath ( row: row, section: section) )
93
114
let pageIndex = CGFloat ( index)
94
115
let progress = pageIndex - currentScrollOffset
95
116
var zIndex = Int ( - abs( round ( progress) ) )
You can’t perform that action at this time.
0 commit comments