[英]iOS7 UICollectionView how to move a single cell to a different section with animation?
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:
? 您是否看过
-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. 您似乎正在更改支持集合视图的数据,然后依靠
-reloadSections:
更新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. 由于您确切知道已执行了哪些更改,因此至少可以使用
-deleteItemsAtIndexPaths:
和-insertItemsAtIndexPaths:
来指示删除和重新插入该图像的确切位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.