繁体   English   中英

更改CollectionView单元的垂直间距

[英]Change Vertical Spacing of CollectionView Cell

我正在使用UICollectionView并在这样的集合视图的委托方法中更改项目的大小

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

    lastIndex = 0;
    layoutDiff = 4;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == (lastIndex + layoutDiff) - 1){
        layoutDiff = (layoutDiff == 4)?5:4;
        lastIndex = indexPath.row + 1;
        return CGSizeMake(213.2, 213.2);
    }

    return CGSizeMake(106.6, 106.6);
}

这是我当前的屏幕

在此处输入图片说明

并且下面的所有单元格都遵循此行为,这意味着我想要的模式就像一个集合视图项一样大,具体取决于我想将其设为大但我不希望有这个空间的逻辑。 我认为如果空间不存在,那么一切都会正确。 有人能帮忙吗?

FlowLayout对此无能为力。

您必须实现UICollectionLayout的子类。

以下是一些有关自定义“收藏夹视图布局”的文章。

自定义集合视图布局。

https://www.objc.io/issues/3-views/collection-view-layouts/

知道何时对流布局进行子类化https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/UsingtheFlowLayout/UsingtheFlowLayout.html#//apple_ref/doc/uid/TP40012334-CH3-SW4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM