方法一:
[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];
方法一和方法二的區(qū)別:方法一會看不見當前section的頭部巢音,方法二可以
效果圖:
方法一
1
方法二
2