Skip to content

Commit b33d93b

Browse files
author
jinyu
committed
Bugfix for "Get wrong minimumInteritemSpacing when have multi-section"
1 parent 429e876 commit b33d93b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Example/Example/ExampleViewController.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ - (void)viewWillDisappear:(BOOL)animated
5858

5959
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
6060
{
61-
return 1;
61+
return 2;
6262
}
6363

6464
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
6565
{
66-
return 100;
66+
return section == 0 ? 20 : 80;
6767
}
6868

6969
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
@@ -86,7 +86,7 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
8686

8787
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
8888
{
89-
return 5;
89+
return section == 0 ? 15 : 5;
9090
}
9191

9292
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde
8585
}
8686

8787
CGRect frame = currentItemAttributes.frame;
88-
frame.origin.x = previousFrameRightPoint + [self evaluatedMinimumInteritemSpacingForItemAtIndex:indexPath.row];
88+
frame.origin.x = previousFrameRightPoint + [self evaluatedMinimumInteritemSpacingForSectionAtIndex:indexPath.section];
8989
currentItemAttributes.frame = frame;
9090
return currentItemAttributes;
9191
}
9292

93-
- (CGFloat)evaluatedMinimumInteritemSpacingForItemAtIndex:(NSInteger)index
93+
- (CGFloat)evaluatedMinimumInteritemSpacingForSectionAtIndex:(NSInteger)section
9494
{
9595
if ([self.collectionView.delegate respondsToSelector:@selector(collectionView:layout:minimumInteritemSpacingForSectionAtIndex:)]) {
9696
id<UICollectionViewDelegateLeftAlignedLayout> delegate = (id<UICollectionViewDelegateLeftAlignedLayout>)self.collectionView.delegate;
9797

98-
return [delegate collectionView:self.collectionView layout:self minimumInteritemSpacingForSectionAtIndex:index];
98+
return [delegate collectionView:self.collectionView layout:self minimumInteritemSpacingForSectionAtIndex:section];
9999
} else {
100100
return self.minimumInteritemSpacing;
101101
}

0 commit comments

Comments
 (0)