我试图动画重新排序在iOS 6中UICollectionView项目。
我写了这个代码:
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];
因此,首先,我节省了项目的所有当前的位置在一本字典,然后我排序的项目到新的位置,然后我会在所有的项目,并从旧位置到新的移动它们。
当显示在屏幕上的所有项目这个伟大的工程,但如果在列表中,如果再然后是10,这使得一些项目,目前看不到(因为它们的上方或下方的列表的可见部分),它会导致这些项目突然蹦出成可见的指标存在并获得动画到其他地方,和动画停止时,他们是隐藏的。 这看起来真的很怪异,因为有出现在他人之上的项目...
这是与iOS 6 UICollectionView一个问题,我在错在这里做什么?