UICollectionView滚动到指定Cell不生效问题

问题描述:

在页面将要出现的时候,调用scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animatedUICollectionView滚动到指定的cell上不生效

解决:

scrollToItemAtIndexPath:之前先调用

[self.collectionView layoutIfNeeded];
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];

然后就可以正常滚动到指定的cell了.

这里[self.collectionView layoutIfNeeded];如果换成[self layoutIfNeeded];并不能正常的滚动到指定的位置

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。