
答:调用此方法可滚动到组头
-(void) scrollToSectionHeader:(int)section {
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:0 inSection:section];
UICollectionViewLayoutAttributes *attribs =
[self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath];
CGPoint topOfHeader = CGPointMake(0, attribs.frame.origin.y -
self.collectionView.contentInset.top);
[self.collectionView setContentOffset:topOfHeader animated:YES];
}
本文介绍了一个用于iOS开发的方法,该方法能够使UICollectionView滚动到指定的组头部位置。通过使用NSIndexPath与UICollectionViewLayoutAttributes,可以精确地定位并滚动到目标位置。
1822

被折叠的 条评论
为什么被折叠?



