iOS 使collection view 滚动到指定的section

方法一:

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:'这里是对应的section值'] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];

方法二:

UICollectionViewLayoutAttributes *attributes = [_collectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForRow:0 '这里是对应的section值']];
    CGRect rect = attributes.frame;
    [_collectionView setContentOffset:CGPointMake(_collectionView.frame.origin.x, rect.origin.y - '这里是对应的section header高度') animated:YES];

方法一和方法二的区别:方法一会看不见当前section的头部,方法二可以
效果图:
方法一

1

方法二
2

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容