From the diagram above I have UICollectionView
with 4 custom cells. At any time 2 or three cells can be on the screen. How can I tell when \"cell 1\"
This will return an Array of IndexPaths for the fully visible cells:
func fullyVisibleCells(_ inCollectionView: UICollectionView) -> [IndexPath] {
var returnCells = [IndexPath]()
var vCells = inCollectionView.visibleCells
vCells = vCells.filter({ cell -> Bool in
let cellRect = inCollectionView.convert(cell.frame, to: inCollectionView.superview)
return inCollectionView.frame.contains(cellRect)
})
vCells.forEach({
if let pth = inCollectionView.indexPath(for: $0) {
returnCells.append(pth)
}
})
return returnCells
}
@IBAction func test(_ sender: Any) {
let visCells = fullyVisibleCells(self.collectionView)
print(visCells)
}