Created
October 17, 2016 19:28
-
-
Save acrookston/ab2b3dcaf67d6bfcf71168f8057916aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UICollectionView { | |
func indexPathsForCloseItems(offset: Int) -> [IndexPath] { | |
var indexes = indexPathsForVisibleItems.sorted(by: { $0.row < $1.row }) | |
for x in indexes { | |
print("had: \(x)") | |
} | |
if let index = indexes.last { | |
for ix in ((index.row + 1)...(index.row + 11)) { | |
let x = createIndexPath(row: ix, section: index.section) | |
indexes.append(x) | |
print("adding: \(x)") | |
} | |
} | |
if let index = indexes.first { | |
for ix in ((index.row - 11)...(index.row - 1)) { | |
let x = createIndexPath(row: ix, section: index.section) | |
indexes.append(x) | |
print("adding: \(x)") | |
} | |
} | |
return indexes | |
} | |
func createIndexPath(row: Int, section: Int) -> IndexPath { | |
let totalRows = numberOfItems(inSection: section) | |
if row > totalRows { | |
return createIndexPath(row: row - totalRows, section: section + 1) | |
} | |
if row < 0 { | |
let prevSectionRows = numberOfItems(inSection: section - 1) | |
return createIndexPath(row: prevSectionRows - abs(row), section: section - 1) | |
} | |
return IndexPath(item: row, section: section) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment