How can i find indexPath for cell in the middle of UICollectionView?
I have horizontal scrolling and only one big cell<
For some of you that might be experiencing some troubles on getting the center, please look at this potential solution:
func centerCell()->UICollectionViewCell? {
// Asuming your scrolling is horizontal
let viewHorizontalCenter = self.view.bounds.width / 2
let center = CGPoint(x: viewHorizontalCenter, y: self.collectionView.center.y)
let convertedPoint = self.view.convert(center, to: self.unitsCollectionView)
let center = CGPoint(x: self.view.bounds.width / 2, y: self.unitsCollectionView.center.y)
let convertedPoint = self.view.convert(center, to: self.unitsCollectionView)
for cell in unitsCollectionView.visibleCells {
if cell.frame.contains(convertedPoint) {
print("Hello")
return cell
}
}
return nil
}