zepojo / UPCarouselFlowLayout

A fancy carousel flow layout for UICollectionView on iOS.
MIT License
1.66k stars 236 forks source link

Cells are not centralizing #26

Open cs-joao-souza opened 6 years ago

cs-joao-souza commented 6 years ago

My cells are not centralizing and have no ideia why.

Do i need to do something special?

dipkasyap commented 6 years ago

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

dubraf commented 6 years ago

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

Ricardo1980 commented 6 years ago

Are you having this problem? https://github.com/ink-spot/UPCarouselFlowLayout/issues/32

armandsLa commented 3 years ago

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