// // QXAgePraizePoolView.m // QXLive // // Created by 启星 on 2025/8/27. // #import "QXAgePraizePoolView.h" @interface QXAgePraizePoolView() @property(nonatomic,strong)UIView* bgView; @property(nonatomic,strong)UIImageView* ruleImageView; @property(nonatomic,strong)UIImageView* bgImageView; @property(nonatomic,strong)UICollectionView* collectionView; @property(nonatomic,strong)QXGiftActivityModel* model; @end @implementation QXAgePraizePoolView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self initSubviews]; } return self; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(void)initSubviews{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; tap.delegate = self; [self addGestureRecognizer:tap]; self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663))]; [self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"age_rule_bg"]]; self.bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663)); self.bgImageView.contentMode = UIViewContentModeScaleToFill; [self.bgView addSubview:self.bgImageView]; self.ruleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"age_pool_icon"]]; self.ruleImageView.contentMode = UIViewContentModeScaleToFill; self.ruleImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(164))/2, 0, ScaleWidth(164), ScaleWidth(90)); [self.bgView addSubview:self.ruleImageView]; [self.bgView addSubview:self.collectionView]; } -(void)setGiftModel:(QXGiftModel *)giftModel{ _giftModel = giftModel; [self getGiftList]; } -(void)setRoomId:(NSString *)roomId{ _roomId = roomId; } -(void)getGiftList{ if (![self.giftModel.gift_bag isExist]) { return; } if (![self.roomId isExist]) { return; } if (self.model) { return; } MJWeakSelf [[QXRequset shareInstance] postWithUrl:[NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/get_gift_list"] parameters:@{@"gift_bag_id":self.giftModel.gift_bag?self.giftModel.gift_bag:@"",@"room_id":self.roomId?self.roomId:@""} needCache:NO success:^(id responseObject) { QXGiftActivityModel *model = [QXGiftActivityModel yy_modelWithJSON:responseObject[@"data"]]; weakSelf.model = model; [self.collectionView reloadData]; } fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) { }]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.model.gift_list.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXAgePoolCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXAgePoolCell" forIndexPath:indexPath]; cell.model = self.model.gift_list[indexPath.row]; return cell; } -(void)showInView:(UIView *)view{ self.bgView.y = SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(663); }]; } -(void)hide{ // [self stopSlowAnimate]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 23; layout.minimumInteritemSpacing = 23; layout.sectionInset = UIEdgeInsetsMake(0, 17, 0, 17); layout.itemSize = CGSizeMake((SCREEN_WIDTH-17*2-23*2-1)/3, ScaleWidth(128)); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.ruleImageView.bottom+10, SCREEN_WIDTH, self.bgView.height-self.ruleImageView.bottom) collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.showsHorizontalScrollIndicator = NO; _collectionView.showsVerticalScrollIndicator = NO; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerClass:[QXAgePoolCell class] forCellWithReuseIdentifier:@"QXAgePoolCell"]; // MJWeakSelf // _collectionView.mj_header = [m footerWithRefreshingBlock:^{ // [weakSelf getGiftList]; // }]; } return _collectionView; } @end @implementation QXAgePoolCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)setModel:(QXDrawGiftModel *)model{ _model = model; [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.base_image]]; self.nameLabel.text = model.gift_name; [self.giftCoin setTitle:[NSString stringWithFormat:@" %@",model.gift_price] forState:(UIControlStateNormal)]; } -(void)initSubviews{ self.giftImageView = [[UIImageView alloc] init]; self.giftImageView.contentMode = UIViewContentModeScaleAspectFit; [self.contentView addSubview:self.giftImageView]; [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self.contentView); make.height.equalTo(self.giftImageView.mas_width); }]; self.nameLabel = [[UILabel alloc] init]; self.nameLabel.textColor = RGB16(0xffffff); self.nameLabel.font = [UIFont systemFontOfSize:12]; [self.contentView addSubview:self.nameLabel]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.giftImageView.mas_bottom); make.centerX.equalTo(self.contentView); }]; self.giftCoin = [[UIButton alloc] init]; [self.giftCoin setTitleColor:RGB16(0xC7BF62) forState:(UIControlStateNormal)]; self.giftCoin.titleLabel.font = [UIFont systemFontOfSize:10]; [self.giftCoin setImage:[UIImage imageNamed:@"age_item_coin"] forState:(UIControlStateNormal)]; [self.contentView addSubview:self.giftCoin]; [self.giftCoin mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.nameLabel.mas_bottom); make.centerX.equalTo(self.contentView); }]; } @end