如何为UICollectionViewCell扩展设置动画?

时间:2017-11-14 16:55:07

标签: ios objective-c uicollectionview uicollectionviewcell uianimation

我有一个UICollectionView。当用户点击一个单元格时,我必须扩展单元格的大小。我是这样做的,

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView performBatchUpdates:^{
        isExpandedMode = true;
        expandedPosition = indexPath.row;
        [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]];
    } completion:^(BOOL finished) {

    }];
}

现在我在这里更新单元格大小,

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if(isExpandedMode && expandedPosition == indexPath.row){
        CGFloat screenWidth = 568.0;
        CGFloat screenHeight = 293.0;
        return CGSizeMake(screenWidth, screenHeight);
    }
    else{
        CGFloat screenWidth = 172.0;
        CGFloat screenHeight = 293.0;
        return CGSizeMake(screenWidth, screenHeight);
    }
}

现在我想将动画应用于单元格的扩展,在哪里编写这段代码?

1 个答案:

答案 0 :(得分:0)

如果您希望对更改进行动画处理,请将其置于performBatchUpdates:completion:

的调用之内