167 lines
6.3 KiB
Objective-C
167 lines
6.3 KiB
Objective-C
//
|
|
// YMGiftCountView.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/11/11.
|
|
//
|
|
|
|
#import "XPGiftCountView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import "NSArray+Safe.h"
|
|
///Model
|
|
#import "XPGiftCountModel.h"
|
|
///View
|
|
#import "XPGiftCountCollectionViewCell.h"
|
|
@interface XPGiftCountView ()<UICollectionViewDelegate, UICollectionViewDataSource>
|
|
//列表
|
|
@property (nonatomic,strong) UICollectionView *countCollectionView;
|
|
///礼物数量数据源
|
|
@property (nonatomic, strong) NSArray<XPGiftCountModel *> *giftCountArray;
|
|
///
|
|
@property (nonatomic,strong) UIVisualEffectView *effectView;
|
|
@end
|
|
|
|
@implementation XPGiftCountView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
// 设置毛玻璃效果
|
|
self.layer.cornerRadius = 12;
|
|
self.layer.masksToBounds = YES;
|
|
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
|
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
|
self.effectView = effectView;
|
|
[self addSubview:effectView];
|
|
self.giftCountArray = [self normalGiftCountDataArray];
|
|
[self addSubview:self.countCollectionView];
|
|
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(0);
|
|
}];
|
|
|
|
[self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.countCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
}
|
|
|
|
///普通礼物的 个数的数据源
|
|
- (NSArray<XPGiftCountModel *> *)normalGiftCountDataArray {
|
|
NSMutableArray * datasource = [NSMutableArray array];
|
|
XPGiftCountModel *_otherDic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView0") giftNumber:@""];
|
|
_otherDic.isCustomCount = YES;
|
|
NSArray * array = [self commonGiftCountDataArray];
|
|
[datasource addObjectsFromArray:array];
|
|
[datasource addObject:_otherDic];
|
|
return [datasource copy];
|
|
}
|
|
|
|
///背包礼物的数据源
|
|
- (NSArray<XPGiftCountModel *> *)packGiftCountDataArray {
|
|
NSMutableArray * datasource = [NSMutableArray array];
|
|
XPGiftCountModel *_allDic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView1") giftNumber:@"all"];
|
|
_allDic.isTotal = YES;
|
|
// 其他数额
|
|
XPGiftCountModel *_otherDic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView2") giftNumber:@""];
|
|
_otherDic.isCustomCount = YES;
|
|
NSArray * array = [self commonGiftCountDataArray];
|
|
[datasource addObjectsFromArray:array];
|
|
[datasource addObject:_allDic];
|
|
[datasource addObject:_otherDic];
|
|
return [datasource copy];
|
|
}
|
|
|
|
///一些公用的数据
|
|
- (NSArray<XPGiftCountModel *> *)commonGiftCountDataArray {
|
|
XPGiftCountModel *_1Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView3") giftNumber:@"1"];
|
|
XPGiftCountModel *_10Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView4") giftNumber:@"10"];
|
|
XPGiftCountModel *_66Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView5") giftNumber:@"66"];
|
|
XPGiftCountModel *_99Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView6") giftNumber:@"99"];
|
|
XPGiftCountModel *_188Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView7") giftNumber:@"188"];
|
|
XPGiftCountModel *_520Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView8") giftNumber:@"520"];
|
|
XPGiftCountModel *_1314Dic = [XPGiftCountModel initCountModel:YMLocalizedString(@"XPGiftCountView9") giftNumber:@"1314"];
|
|
NSArray * array = @[_1Dic, _10Dic, _66Dic, _99Dic,_188Dic,_520Dic, _1314Dic];
|
|
return array;
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.giftCountArray.count;
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPGiftCountCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftCountCollectionViewCell class]) forIndexPath:indexPath];
|
|
XPGiftCountModel *countItem = [self.giftCountArray safeObjectAtIndex1:indexPath.item];
|
|
cell.countModel = countItem;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftCountView:didClickItem:)]) {
|
|
XPGiftCountModel *countItem = [self.giftCountArray safeObjectAtIndex1:indexPath.item];
|
|
[self.delegate xPGiftCountView:self didClickItem:countItem];
|
|
}
|
|
}
|
|
|
|
- (void)setSegmentType:(GiftSegmentType)segmentType {
|
|
_segmentType = segmentType;
|
|
if (_segmentType == GiftSegmentType_Pack) {
|
|
self.giftCountArray = [self packGiftCountDataArray];
|
|
} else {
|
|
self.giftCountArray = [self normalGiftCountDataArray];
|
|
}
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftCountView:didClickItem:)]) {
|
|
XPGiftCountModel *countItem = [self.giftCountArray safeObjectAtIndex1:0];
|
|
[self.delegate xPGiftCountView:self didClickItem:countItem];
|
|
}
|
|
|
|
[self mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(28 * self.giftCountArray.count + 10);
|
|
}];
|
|
|
|
|
|
[self.countCollectionView reloadData];
|
|
|
|
|
|
}
|
|
|
|
-(void)reloadData{
|
|
[self.countCollectionView reloadData];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (UICollectionView *)countCollectionView{
|
|
if (!_countCollectionView) {
|
|
MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(160, 28);
|
|
layout.minimumLineSpacing = 0;
|
|
layout.minimumInteritemSpacing = 0;
|
|
layout.sectionInset = UIEdgeInsetsMake(3, 0, 3, 0);
|
|
_countCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_countCollectionView.dataSource = self;
|
|
_countCollectionView.delegate = self;
|
|
_countCollectionView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
|
|
[_countCollectionView registerClass:[XPGiftCountCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftCountCollectionViewCell class])];
|
|
}
|
|
return _countCollectionView;
|
|
}
|
|
|
|
@end
|