iOS遇到的问题

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

2020-06-02  本文已影响0人  名字不重要呀

问题描述:

在页面将要出现的时候,调用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];并不能正常的滚动到指定的位置

上一篇 下一篇

猜你喜欢

热点阅读