使用动画重新加载集合视图

时间:2013-02-27 06:41:28

标签: objective-c objective-c-blocks uicollectionview

我想用动画重新加载收藏。我浏览了文档,他们提供了以下方法。我用过它。它工作正常。现在我想处理动画的速度(慢/快)。有可能通过这种方法吗?

  - (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion;

我的代码:

[mycollectionView performBatchUpdates:^{
    [mycollectionView reloadData];
   };

3 个答案:

答案 0 :(得分:2)

我不确定,但我认为通过简单地调用performBatchUpdates:真的不可能做到,我认为没有理由覆盖它。

但这样做的简单方法是使单元格透明,然后在animateWithDuration:animations:中调用UIView的collectionView:cellForItemAtIndexPath:

例如:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SMSourceEntityCell";
    SMSourceEntityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.backgroundImageView.alpha = 0.1;
    cell.entityImageView.alpha = 0.1;
    cell.entityImageEffect.alpha = 0.1;

    [UIView animateWithDuration:2.0 animations:^{
        cell.backgroundImageView.alpha = 1;
        cell.entityImageView.alpha = 1;
        cell.entityImageEffect.alpha = 1;
    }];

    return cell;
}

答案 1 :(得分:2)

将移动效果和动画添加到单元格:

 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {

    CGFloat xx=cell.frame.origin.x;
         CGFloat yy=cell.frame.origin.y;



        CGRect frame = cell.frame;
        frame.origin.x = 500; // new x coordinate
        frame.origin.y = 0; // new y coordinate
        cell.frame = frame;


        [UIView animateWithDuration:2.0 animations:^{

            CGRect frame = cell.frame;
            frame.origin.x = xx; // new x coordinate
            frame.origin.y = yy; // new y coordinate
            cell.frame = frame;
            // cell.entityImageEffect.alpha = 1;
        }];

    return cell;

    }

答案 2 :(得分:0)

呼。我有点迟了,但是如果你要缓存单元格的内容,你可以只为尚未缓存的项目设置动画,让缓存的单元格按原样显示。这样,您就不会为重复使用的单元格重复单元格动画。

相关问题