I\'m trying to animate a re-sort of items in UICollectionView on iOS 6.
I wrote this code:
NSMutableDictionary *from = [NSMutableDictionary dicti
It looks like UICollectionView
is reusing cells in such a way as to make your animation look bad. Any cells that go offscreen become available for reuse.
So why is your animation looking funky?
The starting and ending location of a cell, and if it gets hidden or not, is all taken care of automatically when you move cells around. For those animations to look good, you need to also update your data source, as it appears the code uses that to determine where cells should start and end during the animation.
Before you call your index update block, make sure your data source is updated with the new index locations. That way Apple's code has the information it needs to move your cells around in a more, lets say, aesthetically pleasing manner.
From the Apple documentation on UICollectionViews:
To insert, delete, or move a single section or item, you must follow these steps:
- Update the data in your data source object.
- Call the appropriate method of the collection view to insert or delete the section or item.
It is critical that you update your data source before notifying the collection view of any changes. The collection view methods assume that your data source contains the currently correct data. If it does not, the collection view might receive the wrong set of items from your data source or ask for items that are not there and crash your app.