問題描述:
在頁面將要出現(xiàn)的時(shí)候,調(diào)用scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated讓UICollectionView滾動到指定的cell上不生效
解決:
在scrollToItemAtIndexPath:之前先調(diào)用
[self.collectionView layoutIfNeeded];
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
然后就可以正常滾動到指定的cell了.
這里[self.collectionView layoutIfNeeded];如果換成[self layoutIfNeeded];并不能正常的滾動到指定的位置