问题描述:
在页面将要出现的时候,调用scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
让UICollectionView
滚动到指定的cell
上不生效
解决:
在scrollToItemAtIndexPath:
之前先调用
[self.collectionView layoutIfNeeded];
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
然后就可以正常滚动到指定的cell了.
这里[self.collectionView layoutIfNeeded];
如果换成[self layoutIfNeeded];
并不能正常的滚动到指定的位置