// // QXRedBagListView.m // QXLive // // Created by 启星 on 2025/10/11. // #import "QXRedBagListView.h" @interface QXRedBagListView() @property (nonatomic,strong)UIView *bigBgView; @property (nonatomic,strong)UIImageView *bigBgImageView; @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UIImageView *bgImageView; @property (nonatomic,strong)UIImageView *bottomImageView; @property (nonatomic,strong)UIButton *closeBtn; @property (nonatomic,strong)UICollectionView *collectionView; @end @implementation QXRedBagListView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self initSubviews]; } return self; } -(void)initSubviews{ self.bigBgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-375)/2, (SCREEN_HEIGHT-480)/2, 375, 480)]; [self addSubview:self.bigBgView]; self.bigBgImageView = [[UIImageView alloc] initWithFrame:self.bigBgView.bounds]; self.bigBgImageView.image = [UIImage imageNamed:@"red_bag_list_big_bg"]; [self.bigBgView addSubview:self.bigBgImageView]; self.bgView = [[UIView alloc] init]; [self.bgView addRoundedCornersWithRadius:10]; [self.bigBgView addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(280); make.height.mas_equalTo(252); make.centerX.equalTo(self.bigBgView); make.top.mas_equalTo(60); }]; self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 242)]; self.bgImageView.image = [UIImage imageNamed:@"red_bag_list_bg"]; [self.bgView addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.equalTo(self.bgView); make.height.mas_equalTo(242); }]; self.bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_bag_list_bottom_bg"]]; self.bottomImageView.contentMode = UIViewContentModeScaleToFill; [self.bgView addSubview:self.bottomImageView]; [self.bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.equalTo(self.bgView); make.top.equalTo(self.bgImageView.mas_bottom).offset(-1); }]; self.closeBtn = [[UIButton alloc] init]; [self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)]; [self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bigBgView addSubview:self.closeBtn]; [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.top.equalTo(self.bgView.mas_bottom).offset(40); make.height.width.mas_equalTo(30); }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(66,66); layout.minimumLineSpacing =20; layout.minimumInteritemSpacing =16; layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [self.collectionView registerClass:[QXRedBagListCell class] forCellWithReuseIdentifier:@"QXRedBagListCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.backgroundColor = [UIColor clearColor]; [self.bgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.right.mas_equalTo(-25); make.bottom.mas_equalTo(-30); make.top.mas_equalTo(156); }]; } -(void)setDataArray:(NSMutableArray *)dataArray{ _dataArray = dataArray; if (dataArray.count >3) { [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(338); }]; }else{ [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(252); }]; } [self.collectionView reloadData]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXRedBagListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXRedBagListCell" forIndexPath:indexPath]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.didSelectedRedBlock) { self.didSelectedRedBlock(); } [self hide]; } -(void)closeAction{ [self hide]; } -(void)showInView:(UIView *)view{ self.bigBgView.y = -SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.bigBgView.y = (SCREEN_HEIGHT-480)/2; } completion:^(BOOL finished) { }]; } -(void)hide{ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.bigBgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } @end @implementation QXRedBagListCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.contentView.backgroundColor = [UIColor clearColor]; [self initSubviews]; } return self; } -(void)initSubviews{ self.redBagImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_bag_list_icon"]]; [self.contentView addSubview:self.redBagImageView]; [self.redBagImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentView); }]; } @end