繁体   English   中英

iOS7 UICollectionView如何使用动画将单个单元格移动到其他部分?

[英]iOS7 UICollectionView how to move a single cell to a different section with animation?

我有一个应用程序,其中包含用户可以阅读的文章列表。 一旦用户点击了一篇文章,我想将其呈现给用户,然后设置动画,将代表该文章的单元格移动到另一个代表已阅读文章的集合视图部分:

Unread  | Read
0 0 0 0 | X X

下面的代码使所有单元格都重新加载,看起来它们全部都闪烁着背景色。 我是否可以通过动画方式将一个单元格从集合视图的一个部分移动到另一部分?

-(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) {

    }];

}

您是否看过-moveItemAtIndexPath:toIndexPath: 听起来这正是您所需要的。

您似乎正在更改支持集合视图的数据,然后依靠-reloadSections:更新UI。 毫不奇怪,这会重新加载该节中的每个单元。 由于您确切知道已执行了哪些更改,因此至少可以使用-deleteItemsAtIndexPaths:-insertItemsAtIndexPaths:来指示删除和重新插入该图像的确切位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM