Подтвердить что ты не робот

UICollectionViewCell переворачивается и растет на кране

Как я могу достичь анимации, где UICollectionViewCell с переворотом и вырастет, чтобы показать модальное представление при нажатии?

4b9b3361

Ответ 1

Вот что я использовал в другом проекте, и он работал хорошо:

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    if (cell.selected) {
        [collectionView deselectItemAtIndexPath:indexPath animated:YES];
        [UIView transitionWithView:cell
                          duration:0.2
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{
                            [cell setFrame:self.selectedCellDefaultFrame];
                            cell.transform = self.selectedCellDefaultTransform;
                        }
                        completion:^(BOOL finished) {
                            self.selectedCellDefaultFrame = CGRectZero;
                            [collectionView reloadItemsAtIndexPaths:@[indexPath]];
                        }];
        return NO;
    }
    else {
        return YES;
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    [cell.superview bringSubviewToFront:cell];
    self.selectedCellDefaultFrame = cell.frame;
    self.selectedCellDefaultTransform = cell.transform;
    [UIView transitionWithView:cell
                      duration:0.2
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                        [cell setFrame:collectionView.bounds];
                        cell.transform = CGAffineTransformMakeRotation(0.0);
                    }
                    completion:^(BOOL finished) {}];
}

Здесь разные вещи:

  • Вызов сообщения bringSubviewToFront: используется для предотвращения анимации ячейки за другими ячейками.
  • Мы используем два свойства, объявленные в контроллере: selectedCellDefaultFrame и selectedCellDefaultTransform, чтобы сохранить состояние ячейки по умолчанию и повторно инициализировать ее при отмене выбора
  • При отмене выбора мы вызываем метод reloadItemsAtIndexPaths: UICollectionView, чтобы убедиться, что reset позиции полностью завершена

Сообщите мне, есть ли у вас проблемы с этим.

Удачи,

Ответ 2

Я не пробовал анимацию роста, но я думаю, что смогу помочь с анимацией flick UICollectionViewCell.

Try:

UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];

[UIView animateWithDuration:1.0
                      delay:0
                    options:(UIViewAnimationOptionAllowUserInteraction)
                 animations:^
                {
                     NSLog(@"starting animation");

                    [UIView transitionFromView:cell.contentView
                                        toView:newView
                                      duration:.5
                                       options:UIViewAnimationOptionTransitionFlipFromRight
                                    completion:nil];
                }
                 completion:^(BOOL finished)
                {
                     NSLog(@"animation end");
                }
 ];

Надеюсь, что это поможет!