Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

fix issues in iOS 9 #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions DraggableCollectionView/Helpers/LSCollectionViewLayoutHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ - (NSArray *)modifiedLayoutAttributesForElements:(NSArray *)elements
if ([layoutAttributes.indexPath isEqual:hideIndexPath]) {
layoutAttributes.hidden = YES;
}
else {
layoutAttributes.hidden = NO;
}
}

[self rearrangeIndexPathOfLayoutAttributesForElements:elements];

return elements;
}

[self rearrangeIndexPathOfLayoutAttributesForElements:elements];

if (fromIndexPath.section != toIndexPath.section) {
indexPathToRemove = [NSIndexPath indexPathForItem:[collectionView numberOfItemsInSection:fromIndexPath.section] - 1
inSection:fromIndexPath.section];
Expand All @@ -65,6 +73,9 @@ - (NSArray *)modifiedLayoutAttributesForElements:(NSArray *)elements
if ([indexPath isEqual:hideIndexPath]) {
layoutAttributes.hidden = YES;
}
else {
layoutAttributes.hidden = NO;
}
if([indexPath isEqual:toIndexPath]) {
// Item's new location
layoutAttributes.indexPath = fromIndexPath;
Expand Down Expand Up @@ -94,4 +105,40 @@ - (NSArray *)modifiedLayoutAttributesForElements:(NSArray *)elements
return elements;
}

- (void)rearrangeIndexPathOfLayoutAttributesForElements:(NSArray *)elements
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
{
NSComparator cmptr = ^(NSIndexPath *ele1, NSIndexPath *ele2){

if (ele1.section < ele2.section)
return (NSComparisonResult)NSOrderedAscending;

if (ele1.row < ele2.row)
return (NSComparisonResult)NSOrderedAscending;

return (NSComparisonResult)NSOrderedDescending;
};

NSMutableArray *indexPathArray = [NSMutableArray array];

for (UICollectionViewLayoutAttributes *layoutAttributes in elements) {

if([layoutAttributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader]
|| [layoutAttributes.representedElementKind isEqualToString:UICollectionElementKindSectionFooter])
{
continue;
}

[indexPathArray addObject:layoutAttributes.indexPath];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if([layoutAttributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader] || [layoutAttributes.representedElementKind isEqualToString:UICollectionElementKindSectionFooter]) {
continue;
}

Add this check at line 126 (right before you addObject to indexPathArray). The issue is that the header and footer shouldn't have their indexPaths altered as they are always set to a specific indexPath because they are always at the top or bottom of a section.

}

NSArray *sortedArray = [[NSArray arrayWithArray:indexPathArray] sortedArrayUsingComparator:cmptr];

for (NSInteger index = 0; index < sortedArray.count; ++index) {
((UICollectionViewLayoutAttributes*)[elements objectAtIndex:index]).indexPath = (NSIndexPath *)[sortedArray objectAtIndex:index];
}
}
}

@end