MaherKSantina / MSPeekCollectionViewDelegateImplementation

A custom paging behavior that peeks the previous and next items in a collection view
https://medium.com/@maher.santina90/how-to-create-cells-that-peek-on-the-sides-like-ios-11-app-store-ef4bb54c0c7d
MIT License
356 stars 32 forks source link

Where is MSPeekImplementationDelegate now? #58

Closed ElSifi closed 4 years ago

ElSifi commented 4 years ago

Is MSPeekImplementationDelegate deprecated in the latest versions? If so, how to get the current active index?

Thanks.

magicspring commented 4 years ago

I use this way to find the current focus index for now. just add this code in scrollViewWillEndDragging

if let cell = self.collectionView.collectionViewLayout.layoutAttributesForElements(in: CGRect(x: targetContentOffset.move().x, y: targetContentOffset.move().y, width: self.collectionView.frame.size.width, height: self.collectionView.frame.size.height)) {
    if cell.count == 3 { // get middle index
        print(cell[1].indexPath.row)
    } else if cell.count == 2 {
        if self.MSPeekCollectionBehavior.cellPeekWidth == cell[0].frame.origin.x {
            // first index
            print(cell[0].indexPath.row)
        } else {
            // last index
            print(cell[1].indexPath.row)
        }
    } else {

    }
}
ElSifi commented 4 years ago

Thanks @magicspring

I've already fixed it using a similar approach 👌

MaherKSantina commented 4 years ago

Hello @Badi3 and @magicspring ! So sorry for the late reply, I've now pushed a change to the library 3.1.1 that makes it easier to get the current index:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    print(behavior.currentIndex)
}

Have a great day!