Files
featherVoice/QXLive/HomePage(声播)/View/首页/QXHomeTopView.m
2025-10-21 10:29:06 +08:00

236 lines
8.7 KiB
Objective-C

//
// QXHomeTopView.m
// QXLive
//
// Created by 启星 on 2025/10/20.
//
#import "QXHomeTopView.h"
#import "SDCycleScrollView.h"
#import "QXHomeTopRoomCell.h"
@interface QXHomeTopView()<QXHomeTopViewDelegate,SDCycleScrollViewDelegate>
@property (nonatomic,strong)UIImageView *hotRoomImageView;
@property (nonatomic,strong)UIImageView *hotIconImageView;
@property (nonatomic,strong)UILabel *hotLabel;
@property (nonatomic,strong)UIButton *hotRoomBtn;
@property (nonatomic,strong)SDCycleScrollView *roomView;
@property (nonatomic,strong)QXHomeTopSubView *myRoomView;
@property (nonatomic,strong)QXHomeTopSubView *rankView;
@property (nonatomic,strong)QXHomeTopSubView *noticeView;
@end
@implementation QXHomeTopView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.hotRoomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_hot_bg"]];
self.hotRoomImageView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:self.hotRoomImageView];
[self.hotRoomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self);
make.left.mas_equalTo(16);
make.width.mas_equalTo(ScaleWidth(164));
make.height.mas_equalTo(ScaleWidth(184));
}];
self.hotIconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hot_icon"]];
[self addSubview:self.hotIconImageView];
[self.hotIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.hotRoomImageView).offset(12);
make.top.mas_equalTo(20);
make.width.height.mas_equalTo(ScaleWidth(18));
}];
self.roomView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, ScaleWidth(48), (int)ScaleWidth(164), ScaleWidth(184-48)) delegate:self placeholderImage:nil];
self.roomView.backgroundColor = [UIColor clearColor];
self.roomView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
[self.roomView addRoundedCornersWithRadius:8] ;
// self.roomView.pageControlBottomOffset = -10;
self.roomView.showPageControl = NO;
[self addSubview:self.roomView];
[self.roomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self);
make.top.equalTo(self.hotIconImageView.mas_bottom).offset(10);
make.width.equalTo(self.hotRoomImageView);
make.centerX.equalTo(self.hotRoomImageView);
}];
self.hotRoomBtn = [[UIButton alloc] init];
[self.hotRoomBtn setImage:[UIImage imageNamed:@"home_hot_room_goto"] forState:(UIControlStateNormal)];
[self.hotRoomBtn addTarget:self action:@selector(hotRoomAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.hotRoomBtn];
[self.hotRoomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.hotIconImageView);
make.right.equalTo(self.hotRoomImageView);
make.height.mas_equalTo(40);
make.width.mas_equalTo(50);
}];
self.hotLabel = [[UILabel alloc] init];
self.hotLabel.textColor = RGB16(0xF1ECFF);
self.hotLabel.font = [UIFont fontWithName:@"YouSheBiaoTiHei" size:20];
self.hotLabel.text = @"热门房间";
[self addSubview:self.hotLabel];
[self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.hotIconImageView.mas_right);
make.right.equalTo(self.hotRoomBtn.mas_left);
make.centerY.equalTo(self.hotIconImageView);
}];
self.myRoomView = [[QXHomeTopSubView alloc] init];
self.myRoomView.type = QXHomeTopClickTypeMyRoom;
self.myRoomView.delegate = self;
[self addSubview:self.myRoomView];
[self.myRoomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.hotRoomImageView);
make.left.equalTo(self.hotRoomImageView.mas_right).offset(14);
make.right.mas_equalTo(-16);
make.height.mas_equalTo(ScaleWidth(56));
}];
self.rankView = [[QXHomeTopSubView alloc] init];
self.rankView.type = QXHomeTopClickTypeRank;
self.rankView.delegate = self;
[self addSubview:self.rankView];
[self.rankView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.hotRoomImageView);
make.left.right.equalTo(self.myRoomView);
make.height.mas_equalTo(ScaleWidth(56));
}];
self.noticeView = [[QXHomeTopSubView alloc] init];
self.noticeView.type = QXHomeTopClickTypeNotice;
self.noticeView.delegate = self;
[self addSubview:self.noticeView];
[self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.hotRoomImageView);
make.left.right.equalTo(self.myRoomView);
make.height.mas_equalTo(ScaleWidth(56));
}];
}
- (UINib *)customCollectionViewCellNibForCycleScrollView:(SDCycleScrollView *)view{
return [UINib nibWithNibName:@"QXHomeTopRoomCell" bundle:[NSBundle mainBundle]];
}
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{
QXHomeTopRoomCell *roomCell = (QXHomeTopRoomCell*)cell;
roomCell.model = self.dataArray[index];
}
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
QXRoomListModel *model = self.dataArray[index];
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.viewController.navigationController];
}
-(void)setDataArray:(NSArray *)dataArray{
_dataArray = dataArray;
NSMutableArray *arr = [NSMutableArray array];
for (QXRoomListModel *md in dataArray) {
[arr addObject:md.room_cover];
}
self.roomView.imageURLStringsGroup = arr;
}
-(void)didClickTopViewType:(QXHomeTopClickType)type{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickTopViewType:)]) {
[self.delegate didClickTopViewType:type];
}
}
-(void)hotRoomAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickTopViewType:)]) {
[self.delegate didClickTopViewType:QXHomeTopClickTypeHotRoom];
}
}
@end
@implementation QXHomeTopSubView
- (instancetype)init
{
self = [super init];
if (self) {
[self initSubviews];
}
return self;
}
-(void)setType:(QXHomeTopClickType)type{
_type = type;
switch (type) {
case QXHomeTopClickTypeMyRoom:
self.titleLabel.text = @"我的房间";
self.subTitleLabel.text = @"进行一场灵魂深聊";
self.bgImageView.image = [UIImage imageNamed:@"home_my_room_bg"];
break;
case QXHomeTopClickTypeRank:
self.titleLabel.text = @"排行榜";
self.subTitleLabel.text = @"荣耀之巅 彰显实力";
self.bgImageView.image = [UIImage imageNamed:@"home_rank_bg"];
break;
case QXHomeTopClickTypeNotice:
self.titleLabel.text = @"官方公告";
self.subTitleLabel.text = @"政策变动一键留痕";
self.bgImageView.image = [UIImage imageNamed:@"home_notice_bg"];
break;
default:
break;
}
}
-(void)initSubviews{
self.bgImageView = [[UIImageView alloc] init];
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.textColor = RGB16(0xF1ECFF);
self.titleLabel.font = [UIFont fontWithName:@"YouSheBiaoTiHei" size:18];
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bgImageView).offset(11);
make.top.equalTo(self.bgImageView).offset(ScaleWidth(8));
}];
self.subTitleLabel = [[UILabel alloc] init];
self.subTitleLabel.textColor = RGB16(0xF1ECFF);
self.subTitleLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:self.subTitleLabel];
[self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel);
make.bottom.equalTo(self).offset(-ScaleWidth(6));
}];
self.btn = [[UIButton alloc] init];
[self.btn addTarget:self action:@selector(btnAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.btn];
[self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
-(void)btnAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickTopViewType:)]) {
[self.delegate didClickTopViewType:self.type];
}
}
@end