Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current page not get correct #66

Open
aishwarya0786 opened this issue Jul 31, 2020 · 2 comments
Open

current page not get correct #66

aishwarya0786 opened this issue Jul 31, 2020 · 2 comments

Comments

@aishwarya0786
Copy link

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

@richardwei6
Copy link

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.

@alisherFsociety
Copy link

alisherFsociety commented Dec 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants