// // RADetailActionsLayout.m // Apex And Drivers // // Created by Jack on 2018/6/2. // Copyright © 2018年 USAI. All rights reserved. // #import "RADetailActionsLayout.h" @implementation RADetailActionsLayout { NSArray *attrs; } - (void)prepareLayout { if (self.delegate) { attrs = [self.delegate prepareLayout]; } } - (CGSize)collectionViewContentSize { CGFloat height = 0; if (self.delegate) { height = [self.delegate layoutContentHeight]; } return CGSizeMake(self.collectionView.frame.size.width, height); } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { __block NSMutableArray *attrsArr = [NSMutableArray array]; [attrs enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (CGRectIntersectsRect(rect, obj.frame)) { [attrsArr addObject:obj]; } }]; return attrsArr; } - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { return nil; } - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { return nil; } - (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