// // RAPhotoLayout.m // Apex And Drivers // // Created by Jack on 2018/10/30. // Copyright © 2018年 USAI. All rights reserved. // #import "RAPhotoLayout.h" @interface RAPhotoLayout () @property (nonatomic,strong) NSArray *attrs; @end @implementation RAPhotoLayout // 漏写了此方法,导致cell没显示。😓 - (CGSize)collectionViewContentSize { return [self contentSize]; } - (CGSize)contentSize { CGFloat height = 0; if (self.delegate) { height = [self.delegate layoutContentHeight]; } CGSize size = CGSizeMake(self.collectionView.frame.size.width, height); return size; } - (void)prepareLayout { if (self.delegate) { self.attrs = [self.delegate prepareLayout]; } } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { __block NSMutableArray *attrsArr = [NSMutableArray array]; [self.attrs enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (CGRectIntersectsRect(rect, obj.frame)) { [attrsArr addObject:obj]; } }]; return attrsArr; } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *itemtAttrs = [self.attrs objectAtIndex:indexPath.row]; return itemtAttrs; } - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { CGRect oldBounds = self.collectionView.bounds; if (!CGSizeEqualToSize(newBounds.size, oldBounds.size)) { return YES; } return NO; } @end