How to get cell at center during scroll in UICollectionView

Issue #311

See Omnia https://github.com/onmyway133/Omnia/blob/master/Sources/iOS/UICollectionView.swift#L30

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
extension HorizontalUsersViewController: UIScrollViewDelegate {
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let point = view.convert(collectionView.center, to: collectionView)

guard
let indexPath = collectionView.indexPathForItem(at: point),
indexPath.item < users.count
else {
return
}

let user = users[indexPath.item]
delegate?.didScrollTo(user)
}
}

Comments