- (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);
}
网友评论