【发布时间】:2012-12-04 07:49:35
【问题描述】:
我正在尝试在 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 的问题吗,我在这里做错了吗?
【问题讨论】:
标签: ios uicollectionview uicollectionviewcell