188 lines
6.6 KiB
Mathematica
188 lines
6.6 KiB
Mathematica
|
|
//
|
||
|
|
// QXDynamicLikeListView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/6/3.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXDynamicLikeListView.h"
|
||
|
|
#import "QXDynamicNetwork.h"
|
||
|
|
|
||
|
|
@class QXDynamicLikeListCell;
|
||
|
|
@interface QXDynamicLikeListView()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
|
||
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
||
|
|
@property (nonatomic,strong)UIView *bgView;
|
||
|
|
@property (nonatomic,strong)UITableView *tableView;
|
||
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
||
|
|
@property (nonatomic,assign)NSInteger page;
|
||
|
|
@end
|
||
|
|
@implementation QXDynamicLikeListView
|
||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
|
{
|
||
|
|
self = [super initWithFrame:frame];
|
||
|
|
if (self) {
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(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(347);
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
-(void)hide{
|
||
|
|
[UIView animateWithDuration:0.3 animations:^{
|
||
|
|
self.bgView.y = SCREEN_HEIGHT;
|
||
|
|
} completion:^(BOOL finished) {
|
||
|
|
[self removeFromSuperview];
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
QXDynamicLikeListCell *cell = [QXDynamicLikeListCell cellWithTableView:tableView];
|
||
|
|
cell.model = self.dataArray[indexPath.row];
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)initSubviews{
|
||
|
|
self.page = 1;
|
||
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
||
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
||
|
|
tap.delegate = self;
|
||
|
|
[self addGestureRecognizer:tap];
|
||
|
|
|
||
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScaleWidth(347))];
|
||
|
|
self.bgView.backgroundColor = [UIColor whiteColor];
|
||
|
|
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
||
|
|
[self addSubview:self.bgView];
|
||
|
|
|
||
|
|
|
||
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, self.bgView.width-32, 27)];
|
||
|
|
self.titleLabel.textColor = QXConfig.textColor;
|
||
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
|
||
|
|
[self.bgView addSubview:self.titleLabel];
|
||
|
|
|
||
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+5, self.bgView.width, self.bgView.height-self.titleLabel.bottom-5) style:(UITableViewStylePlain)];
|
||
|
|
self.tableView.dataSource = self;
|
||
|
|
self.tableView.delegate = self;
|
||
|
|
self.tableView.rowHeight = 53;
|
||
|
|
MJWeakSelf
|
||
|
|
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
||
|
|
weakSelf.page = 1;
|
||
|
|
[weakSelf getLikeList];
|
||
|
|
}];
|
||
|
|
_tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
||
|
|
weakSelf.page++;
|
||
|
|
[weakSelf getLikeList];
|
||
|
|
}];
|
||
|
|
[self.bgView addSubview:self.tableView];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)setId:(NSString *)Id{
|
||
|
|
_Id = Id;
|
||
|
|
[self getLikeList];
|
||
|
|
}
|
||
|
|
-(void)setNum:(NSString *)num{
|
||
|
|
_num = num;
|
||
|
|
self.titleLabel.text = num;
|
||
|
|
}
|
||
|
|
-(void)getLikeList{
|
||
|
|
MJWeakSelf
|
||
|
|
[QXDynamicNetwork likeListWithId:self.Id page:self.page successBlock:^(NSArray<QXDynamicLikeModel *> * _Nonnull list) {
|
||
|
|
if (weakSelf.page == 1) {
|
||
|
|
[weakSelf.dataArray removeAllObjects];
|
||
|
|
}
|
||
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
||
|
|
if (list.count == 0) {
|
||
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
||
|
|
}else{
|
||
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
||
|
|
}
|
||
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
||
|
|
[weakSelf.tableView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
||
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
||
|
|
}];
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
-(NSMutableArray *)dataArray{
|
||
|
|
if (!_dataArray) {
|
||
|
|
_dataArray = [NSMutableArray array];
|
||
|
|
}
|
||
|
|
return _dataArray;
|
||
|
|
}
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
@implementation QXDynamicLikeListCell
|
||
|
|
|
||
|
|
+(instancetype)cellWithTableView:(UITableView *)tableView{
|
||
|
|
static NSString* cellId = @"QXDynamicLikeListCell";
|
||
|
|
QXDynamicLikeListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
||
|
|
if (!cell) {
|
||
|
|
cell = [[QXDynamicLikeListCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
|
||
|
|
}
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
|
||
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
||
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
-(void)initSubviews{
|
||
|
|
self.headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
||
|
|
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
|
|
[self.headerImageView addRoundedCornersWithRadius:20];
|
||
|
|
[self.contentView addSubview:self.headerImageView];
|
||
|
|
|
||
|
|
self.nameLabel = [[UILabel alloc] init];
|
||
|
|
self.nameLabel.textColor = QXConfig.textColor;
|
||
|
|
self.nameLabel.font = [UIFont systemFontOfSize:14];
|
||
|
|
[self.contentView addSubview:self.nameLabel];
|
||
|
|
|
||
|
|
self.infoLabel = [[UILabel alloc] init];
|
||
|
|
self.infoLabel.textColor = RGB16(0x999999);
|
||
|
|
self.infoLabel.font = [UIFont systemFontOfSize:14];
|
||
|
|
[self.contentView addSubview:self.infoLabel];
|
||
|
|
|
||
|
|
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.mas_equalTo(16);
|
||
|
|
make.size.mas_equalTo(CGSizeMake(40, 40));
|
||
|
|
make.centerY.equalTo(self);
|
||
|
|
}];
|
||
|
|
|
||
|
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.equalTo(self.headerImageView.mas_right).offset(8);
|
||
|
|
make.height.mas_equalTo(21);
|
||
|
|
make.top.equalTo(self.headerImageView).offset(-2);
|
||
|
|
}];
|
||
|
|
|
||
|
|
[self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.equalTo(self.headerImageView.mas_right).offset(8);
|
||
|
|
make.height.mas_equalTo(21);
|
||
|
|
make.top.equalTo(self.nameLabel.mas_bottom);
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
-(void)setModel:(QXDynamicLikeModel *)model{
|
||
|
|
_model = model;
|
||
|
|
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
||
|
|
self.nameLabel.text = model.nickname;
|
||
|
|
self.infoLabel.text = [NSString stringWithFormat:@"%@/%@/%@",model.sex.intValue==1?@"男":@"女",model.age,model.constellation];
|
||
|
|
}
|
||
|
|
@end
|