【问题标题】:UICollectionView: 1 row horizontal scrolling (right to left) with custom animation for new cell coming from rightUICollectionView:1 行水平滚动(从右到左),带有来自右侧的新单元格的自定义动画
【发布时间】:2013-05-21 19:40:53
【问题描述】:
  • 我有一个包含图像的 1 行集合视图
  • 我从右到左滚动图像

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

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

如何实现?

【问题讨论】:

    标签: ios uicollectionview uicollectionviewlayout


    【解决方案1】:

    这可能不是您在动画中想要的,但这是我在 UICollectionViewCell 子类中所做的。这将在单元格中淡出,同时框架缩小到适当的大小。我从collectionView: cellForItemAtIndexPath: 中调用setPhoto 方法。

    @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;
                    }];
                }
            });
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-22
      • 2014-07-16
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      相关资源
      最近更新 更多