0

i want to achieve the result like in this image and this is what I get when I launch the collection view (the first item): enter image description here

But when I scroll the inset left and right seems that aren't respecting anymore and the item is not centered anymore like this:

enter image description here

my part of the code:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

return  CGSize(width: view.bounds.size.width - 60 , height: 450)

}

 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 30)

}

1 Answers1

0

Hi I did understand that you're asking for whenever the collection view is scrolled a little you have to show the next cell completely.

To achieve that in collectionView will display cell

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if !(indexPath.section == 0), !(indexPath.row == 0) {
    let indexPath = IndexPath(item: indexPath.row + 1, section: indexPath.section)
        self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: true)
 }
}

scroll to the next Item.

Hope this may work for you :)

Mohan
  • 41
  • 2
  • Thanks for the reply, but the second image I have uploaded show the collection View at the second item. I haven't scrolled a little like it seems in the image. So what is happening now that when I scroll to another item I don't see the item completely. I want to show the current item completely and also a little of previous item and a little of the next item like in the first image I've uploaded – Vincenzo Flaminio Nov 24 '20 at 11:18