实现collection层叠显示,类似wallet
效果如下
#StickCollectionViewFlowLayout.m
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *oldItems = [super layoutAttributesForElementsInRect:rect];
NSMutableArray *allItems = [[NSMutableArray alloc]initWithArray:oldItems copyItems:YES];
__block UICollectionViewLayoutAttributes *headerAttributes = nil;
[allItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UICollectionViewLayoutAttributes *attributes = obj;
if ([attributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader]) {
headerAttributes = attributes;
}
else {
[self updateCellAttributes:attributes withSectionHeader:headerAttributes];
}
}];
return allItems;
}