Files
fanyin-ios/QXLive/Dynamic(语圈)/View/QXGiveGiftListView.m
2025-08-12 14:27:12 +08:00

237 lines
8.9 KiB
Objective-C

//
// QXGiveGiftListView.m
// QXLive
//
// Created by 启星 on 2025/5/29.
//
#import "QXGiveGiftListView.h"
#import "QXDynamicNetwork.h"
@interface QXGiveGiftListView()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end
@implementation QXGiveGiftListView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(void)initSubviews{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
tap.delegate = self;
[self addGestureRecognizer:tap];
self.backgroundColor = [UIColor clearColor];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, self.width, ScaleWidth(429)+kSafeAreaBottom)];
self.bgView.backgroundColor = [UIColor whiteColor];
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
[self addSubview:self.bgView];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 25, self.width-32, 27)];
self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
self.titleLabel.textColor = RGB16(0x333333);
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.text = QXText(@"打赏榜单");
[self.bgView addSubview:self.titleLabel];
[self.bgView addSubview:self.tableView];
}
-(void)setDynamicId:(NSString *)dynamicId{
_dynamicId = dynamicId;
[self getList];
}
-(void)getList{
MJWeakSelf
[QXDynamicNetwork dynamicGiveGiftListWithId:self.dynamicId successBlock:^(NSArray<QXUserHomeModel *> * _Nonnull list) {
[weakSelf.dataArray removeAllObjects];
[weakSelf.dataArray addObjectsFromArray:list];
[weakSelf.tableView reloadData];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXGiveGiftListCell *cell = [QXGiveGiftListCell cellWithTableView:tableView];
if (indexPath.row == 0) {
cell.rankingImageView.hidden = NO;
cell.rankingLabel.hidden = YES;
cell.rankingImageView.image = [UIImage imageNamed:@"ranking_first"];
}else if (indexPath.row == 1){
cell.rankingImageView.hidden = NO;
cell.rankingLabel.hidden = YES;
cell.rankingImageView.image = [UIImage imageNamed:@"ranking_second"];
}else if (indexPath.row == 2){
cell.rankingImageView.hidden = NO;
cell.rankingLabel.hidden = YES;
cell.rankingImageView.image = [UIImage imageNamed:@"ranking_third"];
}else{
cell.rankingImageView.hidden = YES;
cell.rankingLabel.hidden = NO;
cell.rankingLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
}
QXUserHomeModel *model = self.dataArray[indexPath.row];
cell.model = model;
MJWeakSelf
cell.clickUserBlock = ^(QXUserHomeModel * _Nonnull model) {
[weakSelf hide];
[weakSelf performSelector:@selector(chatAction:) withObject:model afterDelay:0.3];
};
return cell;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
return touch.view == self;
}
-(void)showInView:(UIView *)view{
[view addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429)-kSafeAreaBottom;
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
-(void)chatAction:(QXUserHomeModel*)model{
[[QXGlobal shareGlobal] chatWithUserID:model.user_id nickname:model.nickname avatar:model.avatar navagationController:self.vc.navigationController];
}
-(UITableView *)tableView{
if (!_tableView) {
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+6, self.width, self.height-self.titleLabel.bottom-6) style:UITableViewStylePlain];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = 54;
[self.tableView addRoundedCornersWithRadius:6];
}
return _tableView;
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
@end
@implementation QXGiveGiftListCell
+(instancetype)cellWithTableView:(UITableView*)tableView{
static NSString *cellId = @"QXGiveGiftListCell";
QXGiveGiftListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[QXGiveGiftListCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.rankingImageView = [[UIImageView alloc] init];
[self.contentView addSubview:self.rankingImageView];
[self.rankingImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.size.mas_equalTo(CGSizeMake(16, 16));
make.centerY.equalTo(self);
}];
self.rankingLabel = [[UILabel alloc] init];
self.rankingLabel.font = [UIFont systemFontOfSize:14];
self.rankingLabel.textColor = RGB16(0x666666);
self.rankingLabel.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:self.rankingLabel];
[self.rankingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.height.mas_equalTo(16);
make.centerY.equalTo(self);
make.width.mas_equalTo(25);
}];
self.headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_header_placehoulder"]];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.contentView addSubview:self.headerImageView];
[self.headerImageView addRoundedCornersWithRadius:20];
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rankingImageView.mas_right).offset(12);
make.size.mas_equalTo(CGSizeMake(40, 40));
make.centerY.equalTo(self);
}];
self.followBtn = [[UIButton alloc] init];
[self.followBtn setImage:[UIImage imageNamed:@"expansion_call"] forState:(UIControlStateNormal)];
[self.followBtn addTarget:self action:@selector(followAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.contentView addSubview:self.followBtn];
[self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.height.mas_equalTo(24);
make.width.mas_equalTo(70);
make.right.mas_equalTo(-16);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.font = [UIFont systemFontOfSize:14];
self.nameLabel.textColor = QXConfig.textColor;
[self.contentView addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.headerImageView.mas_right).offset(8);
make.top.equalTo(self.headerImageView.mas_top).offset(-2);
make.height.mas_equalTo(21);
make.right.equalTo(self.followBtn.mas_left).offset(-16);
}];
self.giftLabel = [[UILabel alloc] init];
self.giftLabel.font = [UIFont systemFontOfSize:14];
self.giftLabel.textColor = RGB16(0xF4DF39);
[self.contentView addSubview:self.giftLabel];
[self.giftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.headerImageView.mas_right).offset(8);
make.top.equalTo(self.nameLabel.mas_bottom);
make.height.mas_equalTo(21);
make.right.equalTo(self.followBtn.mas_left).offset(-16);
}];
}
-(void)setModel:(QXUserHomeModel *)model{
_model = model;
self.nameLabel.text = model.nickname;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
self.giftLabel.text = model.total_price;
}
-(void)followAction{
if (self.clickUserBlock) {
self.clickUserBlock(self.model);
}
}
@end