I have an app with a list of articles that a user can read. Once the user taps an article, I want to present it to the user, and then animate moving the cell representing an article to a different collection view section, representing read articles:
Unread | Read
0 0 0 0 | X X
The code below causes all cells to reload, which looks like all of them flashing with background color. Is there a way for me to animate moving once cell from one section of a collection view to another?
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if([collectionView isEqual:self.largeCollectionView])
{
//position the tapped image at the end and animate reload
UIImage* image = largeImages[indexPath.row];
[largeImages removeObjectAtIndex:indexPath.row];
[largeImages addObject:image];
}
[collectionView performBatchUpdates:^{
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:^(BOOL finished) {
}];
}
Have you looked at -moveItemAtIndexPath:toIndexPath:
? It sounds like that provides exactly what you are looking for.
You appear to be changing the data backing your collection view and then relying on -reloadSections:
to update the UI. That unsurprisingly reloads every cell in the section. Since you know exactly what changes you have been performed you could at least use -deleteItemsAtIndexPaths:
and -insertItemsAtIndexPaths:
to indicate exactly where you removed and re-inserted this image.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.