UICollectionView: 1 строка горизонтальной прокрутки (справа налево) с настраиваемой анимацией для новой ячейки справа

  • У меня есть представление коллекций в 1 строку с изображениями
  • Я прокручиваю изображения справа налево

  • Я хотел бы сделать анимацию для каждой ячейки справа (аля Google+)

Эта анимация может быть основана на альфа-канале или расположении кадра.

Как это реализовать?


person fvisticot    schedule 21.05.2013    source источник


Ответы (1)


Это может быть не совсем то, что вы хотите в своих анимациях, но вот что я сделал в подклассе UICollectionViewCell. Это исчезнет в ячейке, в то время как рамка уменьшится до соответствующего размера. Я вызываю метод setPhoto из collectionView: cellForItemAtIndexPath:.

@implementation HistoryCollectionViewCell

- (void)setPhoto:(Photo*)photo {

    if(_photo != photo) {
        _photo = photo;
    }

    // Set up the animations here
    self.photoQueue.alpha = 0.0f;
    self.cellContainerView.alpha = 0.0f;
    CGRect currentFrame = self.cellContainerView.frame;
    CGFloat width = currentFrame.size.width + 20;
    CGFloat height = currentFrame.size.height + 20;
    CGFloat originX = currentFrame.origin.x - 10;
    CGFloat originY = currentFrame.origin.y - 10;
    CGRect newFrame = CGRectMake(originX, originY, width, height);
    self.cellContainerView.frame = newFrame;

    dispatch_queue_t photoQueue = dispatch_queue_create("com.jeremyfox.SnapTo.photoQueue", NULL);
    dispatch_async(photoQueue, ^{

        __block UIImage* image = nil;

        if (_photo) {
            image = [Photo getImageAtPath:_photo.thumbnail];
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            if (image) {
                self.imageView.image = image;

                // Perform the animations here
                [UIView animateWithDuration:0.3f animations:^{
                    self.cellContainerView.alpha = 1.0f;
                    self.cellContainerView.frame = currentFrame;
                }];
            }
        });
    });
}
person Jeremy Fox    schedule 22.05.2013