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 の問題ですか? 何か間違っているのでしょうか?