UPCarouselFlowLayout
UPCarouselFlowLayout copied to clipboard
current page not get correct
I am customizing the frame size then the value of current page is getting wrong.
This worked for me
// UIScrollView Delegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// https://stackoverflow.com/a/38312063/
let centerPoint = CGPoint(x: scrollView.contentOffset.x + (scrollView.frame.width / 2), y: (scrollView.frame.height / 2));
guard let indexPath = collectionView.indexPathForItem(at: centerPoint) else {
return;
}
print("page - \(indexPath.row)");
}
Here's the stack overflow post.
extension UICollectionView {
func getCurrentIndex() ->IndexPath? {
let centerPoint = CGPoint(x: self.contentOffset.x + (self.frame.width / 2), y: (self.frame.height / 2));
return self.indexPathForItem(at: centerPoint)
}
}