collectionView的宽度<每次翻过的宽度
1改变collectionView的宽度为加上间隙宽度
2打开分页属性
- (instancetype)initWithFrame:(CGRect)frame {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = BlockWidth;
frame.size.width += BlockWidth;
self = [super initWithFrame:frame collectionViewLayout:flowLayout];
if(self){
self.pagingEnabled = YES;
}
return self;
}
collectionView的宽度>每次翻过的宽度
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGFloat xOffset = targetContentOffset->x;
CGFloat width = cell.width + minimumLineSpacing;
CGFloat index = xOffset / width;
NSInteger indexInteger = index + 0.5;
targetContentOffset->x = indexInteger * width;
}