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

How to get notify for the current magnified cell index #6

Closed
Evyasafmordechai opened this issue Jul 20, 2018 · 2 comments
Closed

How to get notify for the current magnified cell index #6

Evyasafmordechai opened this issue Jul 20, 2018 · 2 comments

Comments

@Evyasafmordechai
Copy link

No description provided.

@Evyasafmordechai
Copy link
Author

Evyasafmordechai commented Jul 20, 2018

Listen on UIScrollView delegate:

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        let center = self.view.convert(self.collectionView.center, to: self.collectionView)
        guard let indexPath = collectionView.indexPathForItem(at: center) else {
            return
        }
        print("current magnified cell index = \(indexPath.row)")
    }

@Evyasafmordechai
Copy link
Author

Evyasafmordechai commented Jul 21, 2018

If you would like to get notify while scrolling for magnify cell change, do as follow:

    private var lastIndexPathForCenterItem = IndexPath(row: 0, section: 0)

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        callCenterChangedIfNeeded()
    }
    
    private func callCenterChangedIfNeeded() {
        guard let indexPath = indexPathForCenterItem() else {
            return
        }
        guard indexPath != lastIndexPathForCenterItem else {
            return
        }
        lastIndexPathForCenterItem = indexPath
        // Magnify center cell change, do stuff 
    }

    private func indexPathForCenterItem() -> IndexPath? {
        let center = self.view.convert(collectionView.center, to: exploreCollectionView)
        return collectionView.indexPathForItem(at: center)
    }

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

No branches or pull requests

2 participants