Files
featherVoice/QXLive/Room(房间)/View/QXAppstoreHomeView.m

335 lines
13 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXAppstoreHomeView.m
// QXLive
//
// Created by on 2025/8/4.
//
#import "QXAppstoreHomeView.h"
#import "QXHomeRoomCell.h"
#import <SDCycleScrollView.h>
#import "QXBanner.h"
#import "QXTimer.h"
2025-08-08 10:49:36 +08:00
#import "QXHomePageNetwork.h"
@interface QXAppstoreHomeView()<UICollectionViewDelegate,UICollectionViewDataSource,SDCycleScrollViewDelegate>
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)SDCycleScrollView *bannerScrollView;
@property (nonatomic,strong)UIImageView *topImageView;
@property (nonatomic,strong)QXAppstoreRoomView *rommView;
@property (nonatomic,strong)UIImageView *bottomImageView;
//@property (nonatomic,strong)QXAppstoreRoomView *rommView2;
@property (nonatomic,strong)QXRoomListModel *roomModel;
@property (nonatomic,assign)NSInteger currentIndex;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSMutableArray *topArray;
@property (nonatomic,strong)QXTimer *timer;
2025-08-08 10:49:36 +08:00
@end
@implementation QXAppstoreHomeView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:noticeUserLogin object:nil];
self.backgroundColor = [UIColor whiteColor];
self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
[self addSubview:self.scrollView];
[self.scrollView addSubview:self.bannerScrollView];
[self.scrollView addSubview:self.collectionView];
MJWeakSelf
self.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf getTopRoomList];
[weakSelf getAllRoomList];
}];
CGFloat roomWidth = SCREEN_WIDTH-self.collectionView.right-40;
CGFloat roomHeight = roomWidth + 25;
self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_star"]];
self.topImageView.frame = CGRectMake(self.collectionView.right+20, self.bannerScrollView.bottom+30, roomWidth, 70);
[self.scrollView addSubview:self.topImageView];
self.rommView = [[QXAppstoreRoomView alloc] initWithFrame:CGRectMake(self.collectionView.right+20, self.topImageView.bottom+10, roomWidth, roomHeight)];
[self.rommView addTapBlock:^(id _Nonnull obj) {
[[QXGlobal shareGlobal] joinRoomWithRoomId:weakSelf.rommView.roomModel.room_id isRejoin:NO navagationController:weakSelf.viewController.navigationController];
}];
[self.scrollView addSubview:self.rommView];
self.bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_star"]];
self.bottomImageView.frame = CGRectMake(self.collectionView.right+20, self.rommView.bottom+10, roomWidth, 70);
self.bottomImageView.transform = CGAffineTransformMakeRotation(M_PI);
[self.scrollView addSubview:self.bottomImageView];
[self getTopRoomList];
[self getAllRoomList];
}
-(void)loginSuccess{
[self getTopRoomList];
[self getAllRoomList];
}
//-(void)startAnimate{
// [self performSelector:@selector(startOptimizedInfiniteFlip) afterDelay:3];
//}
2025-08-08 10:49:36 +08:00
//-(void)setDataArray:(NSArray *)dataArray{
// _dataArray = dataArray;
// [self.collectionView reloadData];
// self.currentIndex = 0;
// self.roomModel = self.dataArray.firstObject;
// self.rommView.roomModel = self.roomModel;
//}
-(void)setBannerArray:(NSArray *)bannerArray{
_bannerArray = bannerArray;
NSMutableArray *arr = [NSMutableArray array];
for (QXBanner *banner in bannerArray) {
[arr addObject:banner.image];
}
self.bannerScrollView.imageURLStringsGroup = arr;
}
- (void)getTopRoomList {
__weak typeof(self)weakSelf = self;
[QXHomePageNetwork homeRoomListWithPage:0 is_top:YES label_id:@"" successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list, BOOL isAppStore) {
if (isAppStore == NO) {
return;
}
[weakSelf.topArray removeAllObjects];
[self.rommView.layer removeAllAnimations];
if (list.count > 0) {
weakSelf.currentIndex = 0;
weakSelf.roomModel = list.firstObject;
weakSelf.rommView.roomModel = weakSelf.roomModel;
[weakSelf.topArray addObjectsFromArray:list];
[weakSelf startTimer];
2025-08-08 10:49:36 +08:00
}
[self.scrollView.mj_header endRefreshing];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
[self.scrollView.mj_header endRefreshing];
}];
}
- (void)getAllRoomList {
__weak typeof(self)weakSelf = self;
[QXHomePageNetwork homeRoomListWithPage:0 is_top:NO label_id:@"" successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list, BOOL isAppStore) {
if (isAppStore == NO) {
return;
}
[weakSelf.dataArray removeAllObjects];
[weakSelf.dataArray addObjectsFromArray:list];
[weakSelf.collectionView reloadData];
[self.scrollView.mj_header endRefreshing];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
[self.scrollView.mj_header endRefreshing];
}];
}
-(void)startTimer{
MJWeakSelf
[self stopTimer];
_timer = [QXTimer scheduledTimerWithTimeInterval:5 repeats:YES queue:dispatch_get_main_queue() block:^{
QXLOG(@"动画3s执行");
[weakSelf startOptimizedInfiniteFlip];
}];
// CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
// scaleAnim.duration = 1.5/2;
// scaleAnim.autoreverses = YES;
// scaleAnim.fromValue = @1.0;
// scaleAnim.toValue = @1.1;
// [self.rommView.layer addAnimation:scaleAnim forKey:@"scaleAnimation"];
}
2025-08-08 10:49:36 +08:00
- (void)startOptimizedInfiniteFlip {
self.currentIndex++;
if (self.currentIndex > self.topArray.count-1) {
self.currentIndex = 0;
}
self.roomModel = self.topArray[self.currentIndex];
//
CGFloat flipDuration = 1.5;
UIViewAnimationOptions flipDirection = UIViewAnimationOptionTransitionFlipFromRight;
// UIViewAnimationOptionTransitionFlipFromLeft;
//
[UIView transitionWithView:self.rommView
duration:flipDuration
options:flipDirection | UIViewAnimationOptionAllowAnimatedContent
animations:^{
self.rommView.roomModel = self.roomModel;
}
completion:^(BOOL finished) {
//
// self.isFront = !self.isFront;
//
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [self startOptimizedInfiniteFlip];
// });
2025-08-08 10:49:36 +08:00
}];
//
}
-(void)stopTimer{
if (_timer) {
[_timer invalidate];
_timer = nil;
}
2025-08-08 10:49:36 +08:00
}
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath];
cell.isAppStore = YES;
cell.model = self.dataArray[indexPath.row];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(ScaleWidth(90), ScaleWidth(90));
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXRoomListModel *model = self.dataArray[indexPath.row];
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.viewController.navigationController];
}
-(UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 15;
layout.minimumInteritemSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, self.bannerScrollView.bottom+10, ScaleWidth(90), SCREEN_HEIGHT-TabbarContentHeight-NavContentHeight-10-ScaleWidth(95)) collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerNib:[UINib nibWithNibName:@"QXHomeRoomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXHomeRoomCell"];
MJWeakSelf
// _collectionView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
// weakSelf.page++;
// [weakSelf getRoomList];
// }];
}
return _collectionView;
}
-(SDCycleScrollView *)bannerScrollView{
if (!_bannerScrollView) {
_bannerScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, 0, SCREEN_WIDTH-32, ScaleWidth(95)) delegate:self placeholderImage:nil];
// _bannerScrollView.backgroundColor = [UIColor redColor];
_bannerScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
[_bannerScrollView addRoundedCornersWithRadius:8] ;
_bannerScrollView.delegate = self;
}
return _bannerScrollView;
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
-(NSMutableArray *)topArray{
if (!_topArray) {
_topArray = [NSMutableArray array];
}
return _topArray;
}
@end
@implementation QXAppstoreRoomView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)setRoomModel:(QXRoomListModel *)roomModel{
_roomModel = roomModel;
[self.roomCoverImageView sd_setImageWithURL:[NSURL URLWithString:roomModel.room_cover]];
self.roomNameLabel.text = roomModel.room_name;
[self.tagImageView sd_setImageWithURL:[NSURL URLWithString:roomModel.label_icon]];
self.hotLabel.text = roomModel.hot_value;
}
-(void)initSubviews{
// self.starImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_star"]];
// [self addSubview:self.starImageView];
// [self.starImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerX.equalTo(self);
// make.top.equalTo(self);
// make.width.height.mas_equalTo(ScaleWidth(70));
// }];
self.roomCoverImageView = [[UIImageView alloc] init];
self.roomCoverImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.roomCoverImageView addRoundedCornersWithRadius:8];
self.roomCoverImageView.image = [UIImage imageNamed:@"user_header_placehoulder"];
[self addSubview:self.roomCoverImageView];
[self.roomCoverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self);
make.width.height.mas_equalTo(self.width);
}];
self.roomNameLabel = [[UILabel alloc] init];
[self addSubview:self.roomNameLabel];
[self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.roomCoverImageView.mas_bottom).offset(5);
make.height.mas_equalTo(20);
make.centerX.equalTo(self);
}];
self.tagImageView = [[UIImageView alloc] init];
[self addSubview:self.tagImageView];
[self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.equalTo(self.roomCoverImageView);
make.height.mas_equalTo(24);
make.width.mas_equalTo(66);
}];
self.hotBgView = [[UIView alloc] init];
self.hotBgView.backgroundColor = RGB16(0x333333);
[self.hotBgView addRoundedCornersWithRadius:12];
[self addSubview:self.hotBgView];
[self.hotBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.right.equalTo(self.roomCoverImageView).offset(-10);
make.width.mas_equalTo(160);
make.height.mas_equalTo(24);
}];
self.hotImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hot_icon"]];
[self.hotBgView addSubview:self.hotImageView];
[self.hotImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(8);
make.centerY.equalTo(self.hotBgView);
make.width.height.mas_equalTo(15);
}];
self.hotLabel = [[UILabel alloc] init];
self.hotLabel.textAlignment = NSTextAlignmentCenter;
self.hotLabel.font = [UIFont systemFontOfSize:13];
self.hotLabel.textColor = [UIColor whiteColor];
[self.hotBgView addSubview:self.hotLabel];
[self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.hotImageView.mas_right).offset(2);
make.right.mas_equalTo(-10);
make.centerY.equalTo(self.hotBgView);
}];
}
@end