【问题标题】:iOS7 UICollectionView how to move a single cell to a different section with animation?iOS7 UICollectionView如何将单个单元格移动到带有动画的不同部分?
【发布时间】:2014-09-14 00:38:16
【问题描述】:

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

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

    }];

}

【问题讨论】:

  • 您是否成功找到了将项目移动到带有动画的另一个部分的方法?

标签: ios objective-c animation ios7 uicollectionview


【解决方案1】:

你看过-moveItemAtIndexPath:toIndexPath:吗?听起来这正是您正在寻找的东西。

您似乎正在更改支持您的集合视图的数据,然后依靠 -reloadSections: 来更新 UI。不出所料,这会重新加载该部分中的每个单元格。既然您确切地知道您进行了哪些更改,您至少可以使用 -deleteItemsAtIndexPaths:-insertItemsAtIndexPaths: 来指明您删除并重新插入此图像的确切位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多