UICollectionViewController - 稍微移动一个单元格而不继承FlowLayout?

时间:2013-09-19 08:45:59

标签: ios objective-c uicollectionview

我有一个简单的UICollectionView,只有四个单元格,使用Flow布局。我只想将#4 100px的单元格向上移动。我是否必须子类化Flow布局,甚至自定义布局才能做到这一点?

实现这一目标的最简单方法是什么?谢谢! 请提供一些示例代码,我不太熟悉Layouts和Collection视图。

2 个答案:

答案 0 :(得分:0)

实施此委托方法:

-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath

然后,您可以更改所需特定单元格的框架

答案 1 :(得分:0)

您可以调整单元格#4的大小,例如:

#pragma mark – UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 4)
        return CGSizeMake(100, 100);
    return CGSizeMake(50, 50);
}

不要忘记在你的.h中实现“UICollectionViewDelegateFlowLayout”(你可以为UICollectionView添加其他的Delegate和DataSource)

@interface MyViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

但是如果您想要子类的集合视图的布局,您可以遵循enter link description here

的示例

++

相关问题