2

我试图找出一种方法来动画删除UICollectionViewCell类似于 iOS 7 中的跳板。被删除的单元格应该缩小成虚无,剩余的单元格应该滑过以填充它的位置(滑动是重要的部分)。我努力了:

• 将每个单元格的框架设置为前一个单元格的框架,如下所示:

UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
CGRect rect = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i - 1 inSection:0]].frame;      
[UIView animateWithDuration:0.2 animations:^{
    cell.frame = rect;
}];

但这不起作用,因为细胞根本没有移动。

• 以下两项:

[self.collectionView performBatchUpdates:^{
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];

[UIView animateWithDuration:0.2 animations:^{
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
}];

但是这些使细胞交叉淡化到它们所需的位置,而不是滑动。

我还发现了这个项目,它使用以下内容:

for (int i = index+1; i<[items count]; i++) {
    SEMenuItem *item = [items objectAtIndex:i];
    [UIView animateWithDuration:0.2 animations:^{

        if (i < index + remainingNumberOfItemsInPage) {

            int intVal = item.frame.origin.x;
            if (intVal %3== 0)
                [item setFrame:CGRectMake(item.frame.origin.x+2*item.frame.size.width, item.frame.origin.y-item.frame.size.height-5, item.frame.size.width, item.frame.size.height)];
            else
                [item setFrame:CGRectMake(item.frame.origin.x-item.frame.size.width, item.frame.origin.y, item.frame.size.width, item.frame.size.height)];
        }

        [item updateTag:item.tag-1];
    }];
}

但是,它不在 a 中UICollectionView,所以它对我没有帮助。

注意:我在 iPad 上执行此操作,以防万一它对您很重要。

有任何想法吗?

4

2 回答 2

1

子类UICollectionViewFlowLayout。实施:

- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attr = [self layoutAttributesForItemAtIndexPath:indexPath]; // might need to replace self with super

    attr.transform = CGAffineTransformMakeScale(0, 0);

    return attr;
}
于 2014-07-19T21:48:24.597 回答
0

除了 duci9y 的回答,(使用attr.transform = CGAffineTransformMakeScale(0,0);),以下使瓷砖滑动。我不敢相信我以前没有想到这一点。

[self.collectionView performBatchUpdates:^{
    [self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
    [dataSource removeObjectAtIndex:indexPath.row];
} completion:nil];
于 2014-07-21T01:27:22.320 回答