处理svip

This commit is contained in:
2026-02-04 12:48:18 +08:00
parent 68a610e0a8
commit b4e4b7b606
10 changed files with 817 additions and 10 deletions

View File

@@ -0,0 +1,90 @@
//
// KBSvipFlowLayout.m
// keyBoard
//
// SVIP Section
//
#import "KBSvipFlowLayout.h"
#import "KBSvipBenefitBgView.h"
static NSString * const kKBSvipDecorationViewKind = @"KBSvipBenefitBgDecoration";
@interface KBSvipFlowLayout ()
@property (nonatomic, strong) NSMutableArray<UICollectionViewLayoutAttributes *> *decorationAttributes;
@end
@implementation KBSvipFlowLayout
- (instancetype)init {
if (self = [super init]) {
_decorationSection = 1; // Section 1
[self registerClass:[KBSvipBenefitBgView class] forDecorationViewOfKind:kKBSvipDecorationViewKind];
}
return self;
}
- (void)prepareLayout {
[super prepareLayout];
self.decorationAttributes = [NSMutableArray array];
NSInteger numberOfSections = [self.collectionView numberOfSections];
if (self.decorationSection >= numberOfSections) { return; }
NSInteger numberOfItems = [self.collectionView numberOfItemsInSection:self.decorationSection];
if (numberOfItems == 0) { return; }
// Section Header
UICollectionViewLayoutAttributes *headerAttr = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:self.decorationSection]];
// item
UICollectionViewLayoutAttributes *firstItemAttr = [self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:self.decorationSection]];
UICollectionViewLayoutAttributes *lastItemAttr = [self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:numberOfItems - 1 inSection:self.decorationSection]];
if (!firstItemAttr || !lastItemAttr) { return; }
//
UIEdgeInsets sectionInset = self.sectionInset;
if ([self.collectionView.delegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]) {
sectionInset = [(id<UICollectionViewDelegateFlowLayout>)self.collectionView.delegate collectionView:self.collectionView layout:self insetForSectionAtIndex:self.decorationSection];
}
CGFloat minY = CGRectGetMinY(headerAttr.frame);
CGFloat maxY = CGRectGetMaxY(lastItemAttr.frame) + 16; // 16
CGFloat x = sectionInset.left;
CGFloat width = self.collectionView.bounds.size.width - sectionInset.left - sectionInset.right;
CGRect decorationFrame = CGRectMake(x, minY, width, maxY - minY);
UICollectionViewLayoutAttributes *decorationAttr = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:kKBSvipDecorationViewKind withIndexPath:[NSIndexPath indexPathForItem:0 inSection:self.decorationSection]];
decorationAttr.frame = decorationFrame;
decorationAttr.zIndex = -1; //
[self.decorationAttributes addObject:decorationAttr];
}
- (NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray *attrs = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
for (UICollectionViewLayoutAttributes *decorationAttr in self.decorationAttributes) {
if (CGRectIntersectsRect(rect, decorationAttr.frame)) {
[attrs addObject:decorationAttr];
}
}
return attrs;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
if ([elementKind isEqualToString:kKBSvipDecorationViewKind]) {
for (UICollectionViewLayoutAttributes *attr in self.decorationAttributes) {
if (attr.indexPath.section == indexPath.section) {
return attr;
}
}
}
return [super layoutAttributesForDecorationViewOfKind:elementKind atIndexPath:indexPath];
}
@end