如何以编程方式将UICollectionView滚动到底部?

She*_*101 5 objective-c uiscrollview ios uicollectionview

我有一个UICollectionView.我想在视图出现时滚动到底部.这该怎么做?

有人可以帮我解决这个问题吗?提前致谢.

San*_*ani 8

您可以使用以下代码以UICollectionView编程方式滚动到底部

NSInteger section = [self numberOfSectionsInCollectionView:collectionView] - 1;
NSInteger item = [self collectionView:collectionView numberOfItemsInSection:section] - 1;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
Run Code Online (Sandbox Code Playgroud)