美文网首页
iOS开发-UICollectionView中SectionHe

iOS开发-UICollectionView中SectionHe

作者: 吃不胖的瘦子呀 | 来源:发表于2020-03-27 18:32 被阅读0次

一.

 [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:YES];

二.

UICollectionViewLayoutAttributes *attr = [self.collectionView.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:indexPath.row]];
    UIEdgeInsets insets = self.collectionView.scrollIndicatorInsets;
    CGRect rect = attr.frame;
    rect.size = self.collectionView.frame.size;
    rect.size.height -= insets.top + insets.bottom;
    CGFloat offset = (rect.origin.y + rect.size.height) - self.collectionView.contentSize.height;
    if (offset > 0.0) rect = CGRectOffset(rect, 0, -offset);
    [self.collectionView scrollRectToVisible:rect animated:YES];

三.

 UICollectionViewLayoutAttributes *attribs =
        [self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader
                                                               atIndexPath:[NSIndexPath indexPathForItem:0 inSection:indexPath.row]];
    CGPoint topOfHeader = CGPointMake(0, attribs.frame.origin.y - self.collectionView.contentInset.top);
    [self.collectionView setContentOffset:topOfHeader animated:YES];

相关文章

网友评论

      本文标题:iOS开发-UICollectionView中SectionHe

      本文链接:https://www.haomeiwen.com/subject/ujjruhtx.html