使用
1. 设置UICollectionView 的 layout 为UICollectionViewTetrisLayout
2. 设置UICollectionViewTetrisLayout的代理
UICollectionViewTetrisLayout *tetrisLayout = (UICollectionViewTetrisLayout *)self.collectionViewLayout;
tetrisLayout.delegate = self;
#pragma mark - UICollectionViewDelegateTetrisLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICellMenuItemModel *cellModel = self.arrCellModels[indexPath.row];
return CGSizeMake(cellModel.itemWidth, cellModel.itemHeight);
}
效果
demo地址
github.com/ShiXianjun-…