您好我需要collection view
布局,如下图所示。我创建了一个UICollectionViewFlowLayout
子类并编写了这些代码,但每当我滚动项目时,它们的滚动速度不是2-2,
但我想在每个滚动中滚动2-2页索引。
由于
以下是我的代码:
- (void)awakeFromNib
{
self.minimumInteritemSpacing = 5.0;
self.minimumLineSpacing = 5.0;
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.sectionInset = UIEdgeInsetsMake(0.0, 5.0, 0.0, 5.0);
self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast;
self.itemSize = CGSizeMake((self.collectionView.frame.size.width - self.minimumLineSpacing * 2 - self.sectionInset.left)/2,self.collectionView.frame.size.height);
}
-(CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGFloat offsetAdjustment = MAXFLOAT;
CGFloat horizontalOffset = proposedContentOffset.x;
CGRect targetRect = CGRectMake(proposedContentOffset.x, 0, self.collectionView.bounds.size.width, self.collectionView.bounds.size.height);
NSMutableArray *array = [super layoutAttributesForElementsInRect:targetRect];
for (UICollectionViewLayoutAttributes *layoutAttributes in array) {
CGFloat itemOffset = layoutAttributes.frame.origin.x;
if (ABS(itemOffset - horizontalOffset) < ABS(offsetAdjustment)) {
offsetAdjustment = itemOffset- horizontalOffset - self.sectionInset.left;
}
}
proposedContentOffset.x += offsetAdjustment;
return CGPointMake(proposedContentOffset.x, proposedContentOffset.y);
}