UICollectionView estimatedItemSize - last cell is not aligned

非 Y 不嫁゛ 提交于 2019-11-30 05:43:23

I face a similar issue and the problem was solved by giving a proper minimum inter item spacing, using the delegate methods - minimumInteritemSpacingForSectionAt- of UICollectionViewDelegateFlowLayout.

You are setting estimatedItemSize in the init of view itself.

You need to set it in some controller.

Also,

If all of your cells are the same height, use the itemSize property, instead of this property, to specify the cell size instead.

Documentation: estimatedItemSize

there is a simple method to resolve this. You can add number of prototype cells to check the cell at required position. Once you find the issue at last cell . Check the cell insets in Inspector window.

You call super method but you did not use super returned layoutAttributes.

    [super preferredLayoutAttributesFittingAttributes:layoutAttributes];

You can try to print out original layoutAttributes vs super's layoutAttributes. Sometimes, you don't need to call super function.

Second, You can create custom flowlayout or set inset to let your cell align top. I did this in my project.

You can consider it a Suggestion. According to me the height of UICollectionView is more than UICollectionViewCell Height, thats why its happening. please make them equal them

Custom cell size must be same as that of collection view cell,please check that.It may solve the problem for you.

I have done the similar small project (one raw (1*N) horizontal collection view), here is the github. I hope it would be helpful for your requirement.

https://github.com/texas16/HorizontalCollectionView

Had same problem and what fix it in my case was to make sure :

  1. All cells height are equal.

  2. The collectionView height is bigger then cell height + space between cells.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!