簡體   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