iOS开发

iOS 使collection view 滚动到指定的secti

2020-01-10  本文已影响0人  不泯iOS

方法一:

[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
上一篇 下一篇

猜你喜欢

热点阅读