0
  • 我有一个带有图像的 1 行集合视图
  • 我从右到左滚动图像

  • 我想为来自右侧的每个单元格制作动画(ala Google+)

此动画可以基于 Alpha 或帧位置

如何实施?

4

1 回答 1

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;
                }];
            }
        });
    });
}
于 2013-05-22T00:39:07.487 回答