我希望我的UICollectionView自动滚动到底部。我在viewDidAppear中有这个代码但是当我运行它时,在显示视图和集合视图滚动到底部之间总是有半秒的暂停。我读了其他问题但还没有找到答案。有人有想法吗?
- (void)viewDidAppear:(BOOL)animated{
NSInteger numbersOfItems = self.photoAssets.count - 1;
NSLog(@"%i", [self.collectionView numberOfItemsInSection:0]);
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:numbersOfItems inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
}
答案 0 :(得分:1)
你的细胞是否快速初始化?可能发生的是可见单元格(顶部)正在创建,然后一些额外的单元格必须被创建,并且它减慢了滚动的感知时间。您可能希望降低其复杂性,和/或在将项目加载到集合视图后立即滚动到项目,而不是等待viewDidAppear。
答案 1 :(得分:0)
您是否尝试过调用此代码,即viewDidLoad?
NSInteger numbersOfItems = self.photoAssets.count - 1;
NSLog(@"%i", [self.collectionView numberOfItemsInSection:0]);
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:numbersOfItems inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
有关视图加载过程的详细信息,请查看this guide