How can i find indexPath
for cell
in the middle of UICollectionView
?
I have horizontal scrolling and only one big cell<
Try this protocol...
protocol CollectionVisibleMidCell {}
extension CollectionVisibleMidCell where Self: UICollectionView {
func getMidVisibleIndexPath() -> IndexPath? {
var visibleRect = CGRect()
visibleRect.origin = self.contentOffset
visibleRect.size = self.bounds.size
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
guard let indexPath = self.indexPathForItem(at: visiblePoint) else { return nil }
return indexPath
}
}
extension UICollectionView: CollectionVisibleMidCell {}