Skip to content

Commit 5ab8dcb

Browse files
committed
Improve layoutAttributesForElementsInRect implementation
See mokagio#5 (comment)
1 parent f82b11e commit 5ab8dcb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ @implementation UICollectionViewLeftAlignedLayout
4444
#pragma mark - UICollectionViewLayout
4545

4646
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
47-
NSMutableArray* attributesToReturn = [NSMutableArray array];
48-
for (UICollectionViewLayoutAttributes* attributes in [super layoutAttributesForElementsInRect:rect]) {
49-
UICollectionViewLayoutAttributes* attributesCopy = [attributes copy];
50-
if (nil == attributesCopy.representedElementKind) {
51-
NSIndexPath* indexPath = attributesCopy.indexPath;
52-
attributesCopy.frame = [self layoutAttributesForItemAtIndexPath:indexPath].frame;
47+
NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];
48+
NSMutableArray *updatedAttributes = [NSMutableArray arrayWithArray:originalAttributes];
49+
for (UICollectionViewLayoutAttributes *attributes in originalAttributes) {
50+
if (!attributes.representedElementKind) {
51+
NSUInteger index = [updatedAttributes indexOfObject:attributes];
52+
updatedAttributes[index] = [self layoutAttributesForItemAtIndexPath:attributes.indexPath];
5353
}
54-
[attributesToReturn addObject:attributesCopy];
5554
}
56-
return attributesToReturn;
55+
56+
return updatedAttributes;
5757
}
5858

5959
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {

0 commit comments

Comments
 (0)