DecorationView

#import 

NS_ASSUME_NONNULL_BEGIN

@interface CGCSectionLayout : UICollectionViewFlowLayout

@end

NS_ASSUME_NONNULL_END

#import "CGCSectionLayout.h"
#import "CGCSectionBackgroundView.h"
#import "CGCSectionABackground.h"
#import "CGCSectionBBackground.h"
#import "CGCSectionCBackground.h"

NSString *decorationViewOfKind = @"decorationBgView";

@interface CGCSectionLayout ()
@property (nonatomic, strong) NSMutableArray *itemsAttribute;
@end

@implementation CGCSectionLayout

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self registerClass:[CGCSectionBackgroundView class] forDecorationViewOfKind:decorationViewOfKind];
        [self registerClass:[CGCSectionABackground class] forDecorationViewOfKind:@"CGCSectionABackground"];
        [self registerClass:[CGCSectionBBackground class] forDecorationViewOfKind:@"CGCSectionBBackground"];
    }
    return self;
}

-(void)prepareLayout{
    [super prepareLayout];
    NSLog(@"prepareLayout..:%@ ",[NSDate date]);
    self.itemsAttribute=[NSMutableArray new];
    NSInteger numberOfSection=self.collectionView.numberOfSections;
    for (int section=0; section *)layoutAttributesForElementsInRect:(CGRect)rect{
    NSMutableArray *attributes=[NSMutableArray arrayWithArray:[super layoutAttributesForElementsInRect:rect]];
    for (UICollectionViewLayoutAttributes *attribute in self.itemsAttribute) {
        if (CGRectIntersectsRect(rect, attribute.frame)) {
            [attributes addObject:attribute];
        }
    }
    return attributes;
}


@end

你可能感兴趣的:(DecorationView)