I am trying to revive the re-sorting of elements in a UICollectionView on iOS 6.
I wrote this code:
NSMutableDictionary *from = [NSMutableDictionary dictionaryWithCapacity:self.count]; for (int ii = 0; ii < self.count; ii++) { MyItem item = [self getItemAtIndex:(NSInteger)ii]; [from setObject:[NSNumber numberWithInt:ii] forKey:[NSNumber numberWithInt:item.id]]; } [self sort]; [self.collectionView performBatchUpdates:^{ for (int ii = 0; ii < self.count; ii++) { MyItem item = [self getItemAtIndex:(NSInteger)ii]; NSNumber *prevPos = (NSNumber *)[from objectForKey:[NSNumber numberWithInt:item.id]]; if ([prevPos intValue] != ii) { NSIndexPath *from = [NSIndexPath indexPathForItem:prevPos.intValue inSection:0]; NSIndexPath *to = [NSIndexPath indexPathForItem:ii inSection:0]; [self.collectionView moveItemAtIndexPath:from toIndexPath:to]; } } } completion:nil];
So, firstly, I save all the current locations of elements in the dictionary, then sort the elements in new positions, then I look through all the elements and move them from the old position to the new one.
This works fine when all the elements are displayed on the screen, but if the list is longer than 10, which makes some elements that are not currently visible (because they are above or below the visible section of the list), it causes these elements to suddenly appear in visible indices and animate in other places, and when the animation stops, they are hidden. It looks really weird because there are objects that appear on top of others ...
Is this a problem with iOS 6 UICollectionView and am I doing something wrong here?
ios uicollectionview uicollectionviewcell
marmor Dec 04 2018-12-12T00: 00Z
source share