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];并不能正常的滚动到指定的位置

你可能感兴趣的:(UICollectionView滚动到指定Cell不生效问题)