这只是一个“布局”,也就是说你还需要自己提供一个viewController和一个collectionView,然后把这3个东西包起来!
这是一个示例:在您的 WaterfallViewController.h
#import "UICollectionViewWaterfallLayout.h"
@interface WaterfallViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, UICollecitonViewDelegateWaterfallLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
在你的 WaterfallViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UICollectionViewWaterfallLayout *layout = [[UICollectionViewWaterfallLayout alloc] init];
layout.delegate = self;
layout.columnCount = 2;
layout.itemWidth = 146;
layout.sectionInset = UIEdgeInsetsMake(9, 9, 9, 9);
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@"MyCell"];
[self.view addSubview:self.collectionView];
}
#pragma mark - UICollecitonViewDelegateWaterfallLayout Delegate
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewWaterfallLayout *)collectionViewLayout
heightForItemAtIndexPath:(NSIndexPath *)indexPath
{
// return the height for cell at indexPath.
}
很抱歉给您带来不便,我会尽快在 repo 中添加一些示例代码。