2

カスタム レイアウトを使用して、UICollectionViewCells を次のように配置しています。

ここに画像の説明を入力

これはうまくいきます。ここで、左下隅にあるボタンを押すと、次のように、すべてのセルがアニメーションでビューの中央に戻ります。

ここに画像の説明を入力

私はこれを機能させていますが、まったくアニメーション化していません。それはそのようにちょっとポップします。リロードアクションに使用しているコードは次のとおりです。

- (IBAction)animate:(id)sender {
[self.collectionView performBatchUpdates:^{
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
}

私のレイアウトクラスには、次のlayoutAttributesForItemAtIndexPathようにセルの中心を調整する prepareLayout が呼び出されるたびに反転するフラグがあります。

- (UICollectionViewLayoutAttributes*) layoutAttributesForItemAtIndexPath:(NSIndexPath *)path {
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:path];
attributes.size = CGSizeMake(ITEM_SIZEw, ITEM_SIZEh);

if (self.isCircle) {
    attributes.center = CGPointMake(_center.x +_radius *
                                cosf(2 * path.item * M_PI / _cellCount),
                                _center.y + _radius *
                                sinf(2 * path.item * M_PI/ _cellCount));
} else {
    attributes.center = [self collectionView].center;
}

return attributes;
}

ビューの中心にセルの動きをアニメーション化するにはどうすればよいですか?

4

2 に答える 2

0

次のように UIView アニメーションに変更を加えてみてください。

[UIView animateWithDuration:0.5 animations:^{
   if (self.isCircle) {
       attributes.center = CGPointMake(_center.x +_radius *
                                cosf(2 * path.item * M_PI / _cellCount),
                                _center.y + _radius *
                                sinf(2 * path.item * M_PI/ _cellCount));
   } else {
       attributes.center = [self collectionView].center;
   }
}];
于 2013-07-31T20:40:54.810 に答える