RADetailActionsLayout.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // RADetailActionsLayout.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/2.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RADetailActionsLayout.h"
  9. @implementation RADetailActionsLayout {
  10. NSArray *attrs;
  11. }
  12. - (void)prepareLayout {
  13. if (self.delegate) {
  14. attrs = [self.delegate prepareLayout];
  15. }
  16. }
  17. - (CGSize)collectionViewContentSize {
  18. CGFloat height = 0;
  19. if (self.delegate) {
  20. height = [self.delegate layoutContentHeight];
  21. }
  22. return CGSizeMake(self.collectionView.frame.size.width, height);
  23. }
  24. - (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
  25. __block NSMutableArray *attrsArr = [NSMutableArray array];
  26. [attrs enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  27. if (CGRectIntersectsRect(rect, obj.frame)) {
  28. [attrsArr addObject:obj];
  29. }
  30. }];
  31. return attrsArr;
  32. }
  33. - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
  34. return nil;
  35. }
  36. - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
  37. return nil;
  38. }
  39. - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
  40. UICollectionViewLayoutAttributes *itemtAttrs = [self->attrs objectAtIndex:indexPath.row];
  41. return itemtAttrs;
  42. }
  43. - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
  44. CGRect oldBounds = self.collectionView.bounds;
  45. if (!CGSizeEqualToSize(newBounds.size, oldBounds.size)) {
  46. return YES;
  47. }
  48. return NO;
  49. }
  50. @end