美文网首页
UICollectionView 自定义分页

UICollectionView 自定义分页

作者: OS羽 | 来源:发表于2021-06-30 14:58 被阅读0次

    - (void)prepareLayout {

        [super prepareLayout];

        self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast;

        self.collectionView.pagingEnabled = false;

    }

    - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {

        CGFloat pageWidth = self.itemSize.width + self.minimumLineSpacing;

        CGFloatapproximatePage =self.collectionView.contentOffset.x/ pageWidth;

        CGFloatcurrentPage = velocity.x==0?round(approximatePage) : (velocity.x<0.0?floor(approximatePage) :ceil(approximatePage));

        CGFloat margin = (self.collectionView.bounds.size.width - self.itemSize.width) * 0.5;

        CGFloatnewHorizontalOffset =self.sectionInset.left+ currentPage * pageWidth - margin;

        returnCGPointMake(newHorizontalOffset, proposedContentOffset.y);

    }

    相关文章

      网友评论

          本文标题:UICollectionView 自定义分页

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