【发布时间】:2015-07-21 20:16:29
【问题描述】:
我有一个UICollectionView。我想在视图出现时滚动到底部。如何做到这一点?
有人可以帮我解决这个问题吗? 提前致谢。
【问题讨论】:
标签: ios objective-c uiscrollview uicollectionview
我有一个UICollectionView。我想在视图出现时滚动到底部。如何做到这一点?
有人可以帮我解决这个问题吗? 提前致谢。
【问题讨论】:
标签: ios objective-c uiscrollview uicollectionview
您可以使用以下代码以编程方式将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];
【讨论】:
NSIndexPath *lastItem = /*Indexpath of last item*/;
[self.collectionView scrollToItemAtIndexPath:lastItem atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
【讨论】:
你把这段代码滑下来。
NSArray *visibleItems = [self.collectionView indexPathsForVisibleItems];
NSIndexPath *currentItem = [visibleItems objectAtIndex:0];
NSIndexPath *nextItem = [NSIndexPath indexPathForItem:currentItem.item + 1 inSection:currentItem.section];
[self.collectionView scrollToItemAtIndexPath:nextItem atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
【讨论】:
设置集合视图对象的contentoffset.y。
【讨论】: