Files
midi_ios/QXLive/活动/巡乐会/QXMeetActivityResultView.m
2025-10-17 11:41:09 +08:00

203 lines
7.5 KiB
Objective-C

//
// QXMeetActivityResultView.m
// QXLive
//
// Created by 启星 on 2025/8/30.
//
#import "QXMeetActivityResultView.h"
@interface QXMeetActivityResultView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)UIButton *againBtn;
@property (nonatomic,strong)UIButton *closeBtn;
@end
@implementation QXMeetActivityResultView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bgView = [[UIView alloc] init];
[self addSubview:self.bgView];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.height.mas_equalTo(430);
make.centerY.equalTo(self);
}];
// @2x
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ac_meet_draw_result_bg"]];
[self.bgView addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(331);
make.height.mas_equalTo(364);
make.top.equalTo(self.bgView);
make.centerX.equalTo(self.bgView);
}];
[self.bgView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.bgImageView);
make.top.mas_equalTo(115);
make.bottom.equalTo(self.bgImageView);
}];
self.againBtn = [[UIButton alloc] init];
[self.againBtn setBackgroundImage:[UIImage imageNamed:@"ac_meet_again_btn"] forState:(UIControlStateNormal)];
[self.againBtn addTarget:self action:@selector(againAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.againBtn];
[self.againBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView);
make.width.mas_equalTo(140);
make.height.mas_equalTo(46);
make.centerX.equalTo(self.bgView);
}];
self.closeBtn = [[UIButton alloc] init];
[self.closeBtn setImage:[UIImage imageNamed:@"ac_meet_result_close"] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.equalTo(self.bgView);
make.height.mas_equalTo(40);
make.width.mas_equalTo(40);
}];
}
-(void)setTimes:(NSString *)times{
_times = times;
}
-(void)setResultArray:(NSArray *)resultArray{
_resultArray = resultArray;
[self.collectionView reloadData];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.resultArray.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXMeetActivityResultCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMeetActivityResultCell" forIndexPath:indexPath];
cell.model = self.resultArray[indexPath.row];
return cell;
}
-(UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 15;
layout.minimumInteritemSpacing = 20;
layout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
layout.itemSize = CGSizeMake((331-12*2-20*2)/3,115);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[QXMeetActivityResultCell class] forCellWithReuseIdentifier:@"QXMeetActivityResultCell"];
}
return _collectionView;
}
-(void)againAction{
[self hide];
if (self.againBlock) {
self.againBlock(self.times);
}
}
-(void)closeAction{
[self hide];
}
-(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];
// }];
}
@end
@implementation QXMeetActivityResultCell
- (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.giftNameLabel.text = [NSString stringWithFormat:@"%@x%@",model.gift_name,model.count];
[self.giftCoin setTitle:model.gift_price forState:(UIControlStateNormal)];
}
-(void)initSubviews{
self.giftBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ac_gif_box_bg"]];
[self.contentView addSubview:self.giftBgImageView];
[self.giftBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.contentView);
make.height.equalTo(self.giftBgImageView.mas_width);
}];
self.giftImageView =[[UIImageView alloc] init];
self.giftImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:self.giftImageView];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(50);
make.centerX.centerY.equalTo(self.giftBgImageView);
}];
self.giftInfoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ac_gift_info_bg"]];
[self.contentView addSubview:self.giftInfoImageView];
[self.giftInfoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView);
make.height.mas_equalTo(30);
make.bottom.equalTo(self.contentView);
}];
self.giftNameLabel = [[UILabel alloc] init];
self.giftNameLabel.textColor = RGB16(0xffffff);
self.giftNameLabel.font = [UIFont systemFontOfSize:12];
self.giftNameLabel.textAlignment = NSTextAlignmentCenter;
self.giftNameLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
[self.contentView addSubview:self.giftNameLabel];
[self.giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.giftBgImageView.mas_bottom);
make.left.right.equalTo(self.contentView);
}];
self.giftCoin = [[UIButton alloc] init];
[self.giftCoin setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
self.giftCoin.titleLabel.font = [UIFont systemFontOfSize:10];
[self.giftCoin setImage:[UIImage imageNamed:@"sky_item_coin"] forState:(UIControlStateNormal)];
[self.contentView addSubview:self.giftCoin];
[self.giftCoin mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.giftNameLabel.mas_bottom);
make.centerX.equalTo(self.contentView);
}];
}
@end