简体   繁体   English

更改CollectionView单元的垂直间距

[英]Change Vertical Spacing of CollectionView Cell

Am using UICollectionView and changing the size of the item in the delegate method of collection view like this 我正在使用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);
}

and here is my current screen. 这是我当前的屏幕

在此处输入图片说明

and all the below cells to be follow this behaviour, means the pattern i want is like one collection view item to big depending on my logic where i want to make it big but i don't want this space. 并且下面的所有单元格都遵循此行为,这意味着我想要的模式就像一个集合视图项一样大,具体取决于我想将其设为大但我不希望有这个空间的逻辑。 I think if the space will not b there then all things will be right. 我认为如果空间不存在,那么一切都会正确。 Can anyone help with this? 有人能帮忙吗?

FlowLayout can't help with this. FlowLayout对此无能为力。

You hava to implement your subclass of UICollectionLayout. 您必须实现UICollectionLayout的子类。

Here are some articles that take about custom Collection View Layout. 以下是一些有关自定义“收藏夹视图布局”的文章。

Custom Collection View Layouts. 自定义集合视图布局。

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

Knowing When to Subclass the Flow Layout https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/UsingtheFlowLayout/UsingtheFlowLayout.html#//apple_ref/doc/uid/TP40012334-CH3-SW4 知道何时对流布局进行子类化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