简体   繁体   English

我如何制作交错的UICollectionView?

[英]How would I make a staggered UICollectionView?

How would I create a staggered UICollectionView with the code I currently have? 如何使用当前的代码创建交错的UICollectionView?

- (void)viewDidLoad
{
    [self.collectionViewPack registerNib:[UINib nibWithNibName:@"CollectionViewItem" bundle:nil] forCellWithReuseIdentifier:kCellReuseIdentifier];
    self.collectionViewPack.backgroundColor = [UIColor whiteColor];

    [super viewDidLoad];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(150, 250)];
    [flowLayout setSectionInset:UIEdgeInsetsMake(8, 5, 5, 5)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

    [self.collectionViewPack setCollectionViewLayout:flowLayout];
    [self.collectionViewPack setAllowsSelection:YES];
    self.collectionViewPack.delegate=self;
}

I'd like the columns to be able to scroll independently in their respective columns, but if that's not possible then staggered would be awesome too. 我希望这些列能够在它们各自的列中独立滚动,但是如果那不可能,那么交错也是很棒的。 Any ideas? 有任何想法吗?

You can follow the same method here as described for UITableView 您可以在此处遵循与UITableView所述相同的方法

https://stackoverflow.com/a/18746930/1616513 https://stackoverflow.com/a/18746930/1616513

Then in sizeForItemAtIndexPath: 然后在sizeForItemAtIndexPath:

You just ask the cell to lay itself out and then call systemLayoutFittingSize on the cells contentView to get the calculated size. 您只需要求单元格进行布局,然后在单元格contentView上调用systemLayoutFittingSize即可获得计算出的大小。

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

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