2012-12-03 13 views
5

UICollectionView内のすべてのセルをアニメーション化するにはどうすればよいのでしょうか。私はUICollectionViewでの編集をシミュレートしようとしています。だから私がしたいことは、UICollectionViewCellのすべての境界を縮小することです。UICollectionView内のすべてのUICollectionViewCellをアニメーション化する

- (IBAction)startEditingMode:(id)sender { 
    [_items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; 
     UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; 

     [UIView animateWithDuration:0.25 animations:^{ 
      cell.layer.transform = CATransform3DMakeScale(0.9, 0.9, 1); 
     }]; 
    }]; 
} 

それは動作しますが、UICollectionViewのプロパティ、またはこのような何かを行うには良い、より標準的な方法があったかどうかわかりませんでした。だから、私が持っていることはこれです。ありがとう。

答えて

0

UICollectionView performBatchUpdates:を試しましたか?私はUICollectionViewLayoutサブクラスを作成します

[collectionView performBatchUpdates:^{ 
    [_items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; 
     UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; 
     cell.layer.transform = CATransform3DMakeScale(0.9, 0.9, 1); 
    }]; 
} completion:^{}]; 
1

:よう

何か。編集というBOOLプロパティを追加します。変更を編集するときは、invalidateLayoutを呼び出します。次に、-layoutAttributesForItemAtIndexPath:メソッドによって返される属性で、トランスフォームを指定できます。

あなたのアプローチの問題は、可視のセルにのみ影響することです。 UICollectionViewLayoutサブクラスは、新しいセルが追加されてもすべてのセルにトランスフォームを適用するため、優れています。また、コレクションビューレイアウト処理のすべてをビューコントローラから移動します。

セルの属性には、フレーム、サイズ、中心、変形(3D)、アルファ、独自のカスタム属性を含めることができます。

wL_のように、-performBatchUpdates:ブロックの編集値を変更します。

- (IBAction)startEditingMode:(id)sender { 
    [self.collectionView performBatchUpdates:^{ 
     ((MyCollectionViewLayout *)self.collectionView.collectionViewLayout).editing = YES; 
    } 
    completion:NULL]; 
} 

そしてUICollectionViewLayoutサブクラスで

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 

    if (self.editing) { 
     attributes.transform = CGAffineTransformMakeScale(0.9, 0.9); 
    } 
    else { 
     attributes.transform = CGAffineTransformIdentity; 
    } 

    return attributes; 
} 

はまた、(おそらく)あなたは、3Dがここに変換する必要はありません。アフィン変換で十分です。

関連する問題