UPCarouselFlowLayout icon indicating copy to clipboard operation
UPCarouselFlowLayout copied to clipboard

current page not get correct

Open aishwarya0786 opened this issue 4 years ago • 2 comments

I am customizing the frame size then the value of current page is getting wrong.

aishwarya0786 avatar Jul 31 '20 06:07 aishwarya0786

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.

richardwei6 avatar Apr 09 '21 07:04 richardwei6

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)
    }
}

alisherFsociety avatar Dec 15 '21 10:12 alisherFsociety