2

iOS 7 のスプリングボードと同様に、削除をアニメーション化する方法を見つけようとしていますUICollectionViewCell。削除されたセルは縮小して無になり、残りのセルがスライドしてその場所を埋める必要があります (スライドが重要な部分です)。私が試してみました:

• 次のように、各セルのフレームを前のセルのフレームに設定します。

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];
    }];
}

しかし、それは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 に答える