zepojo/UPCarouselFlowLayout

Cells are not centralizing

Opened this issue · 4 comments

My cells are not centralizing and have no ideia why.

Do i need to do something special?

Same Here Cannot centralize LAST & FIRST , if i make my own design ! Please provide updated info on this issue if possible !

I had the same problem when I was using :
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
The solution was adding sectionInset for the layout inside above method :)

Are you having this problem?
#32

Looks like this is being caused when section insets are not taken into account when sizing the cell. Subtracting them from item size fixes the issue.

func collectionView(_ collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        var height = collectionView.frame.height
        height -= layout.sectionInset.top + layout.sectionInset.bottom
        return CGSize(width: height, height: height)
    }