增加换肤功能
This commit is contained in:
144
QXLive/Mine(音域)/Controller/个性装扮/QXDressSubViewController.m
Normal file
144
QXLive/Mine(音域)/Controller/个性装扮/QXDressSubViewController.m
Normal file
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// QXDressSubViewController.m
|
||||
// QXLive
|
||||
//
|
||||
// Created by 启星 on 2025/5/16.
|
||||
//
|
||||
|
||||
#import "QXDressSubViewController.h"
|
||||
#import "QXDressCell.h"
|
||||
#import "QXMineNetwork.h"
|
||||
#import "QXSeatHeaderView.h"
|
||||
|
||||
@interface QXDressSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
||||
@property (nonatomic,strong)QXSeatHeaderView *headerImageView;
|
||||
@property (nonatomic,strong)UICollectionView *collectionView;
|
||||
@property (nonatomic,strong)UIButton *commitBtn;
|
||||
@property (nonatomic,assign)NSInteger selectedIndex;
|
||||
@end
|
||||
|
||||
@implementation QXDressSubViewController
|
||||
-(UIView *)listView{
|
||||
return self.view;
|
||||
}
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
-(void)initSubViews{
|
||||
self.bgImageHidden = YES;
|
||||
self.selectedIndex = -1;
|
||||
if (self.model.id.intValue == 1) {
|
||||
// 头像
|
||||
[self.view addSubview:self.headerImageView];
|
||||
self.collectionView.frame = CGRectMake(0, self.headerImageView.bottom+25, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44-self.headerImageView.bottom-25);
|
||||
}else{
|
||||
self.collectionView.frame = CGRectMake(0, 12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44);
|
||||
}
|
||||
[self.view addSubview:self.collectionView];
|
||||
[self.view addSubview:self.commitBtn];
|
||||
}
|
||||
|
||||
-(void)getData{
|
||||
MJWeakSelf
|
||||
[QXMineNetwork userDressListWithType:self.model.id successBlock:^(NSArray<QXUserDressModel *> * _Nonnull list) {
|
||||
|
||||
[weakSelf.dataArray addObjectsFromArray:list];
|
||||
if (list.count > 0 ) {
|
||||
QXUserDressModel *model = [[QXUserDressModel alloc] init];
|
||||
model.title = QXText(@"无");
|
||||
model.udid = @"-1";
|
||||
[weakSelf.dataArray insertObject:model atIndex:0];
|
||||
}
|
||||
[weakSelf.collectionView reloadData];
|
||||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||||
return self.dataArray.count;
|
||||
}
|
||||
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||||
QXDressCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXDressCell" forIndexPath:indexPath];
|
||||
cell.model = self.dataArray[indexPath.row];
|
||||
if (indexPath.row == self.selectedIndex) {
|
||||
cell.selecteBtn.selected = YES;
|
||||
}else{
|
||||
cell.selecteBtn.selected = NO;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||||
CGFloat width = (SCREEN_WIDTH-15*2-22*2)/3;
|
||||
return CGSizeMake(width, width/100*120);
|
||||
}
|
||||
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
||||
if (indexPath.row == self.selectedIndex) {
|
||||
return;
|
||||
}
|
||||
QXUserDressModel *model = self.dataArray[indexPath.row];
|
||||
self.selectedIndex = indexPath.row;
|
||||
[collectionView reloadData];
|
||||
// MJWeakSelf
|
||||
|
||||
[self.headerImageView setHeadIcon:[QXGlobal shareGlobal].loginModel.avatar dress:model.play_image];
|
||||
|
||||
}
|
||||
|
||||
-(void)commitAction{
|
||||
QXUserDressModel *model = self.dataArray[self.selectedIndex];
|
||||
BOOL isCancel = NO;
|
||||
if ([model.udid isEqualToString:@"-1"]) {
|
||||
isCancel = YES;
|
||||
}else{
|
||||
isCancel = NO;
|
||||
}
|
||||
MJWeakSelf
|
||||
[QXMineNetwork setUserDressIsCancel:isCancel udid:model.udid type:self.model.id successBlock:^(NSDictionary * _Nonnull dict) {
|
||||
if (weakSelf.model.id.intValue == 1) {
|
||||
[QXGlobal shareGlobal].loginModel.dress = model.play_image;
|
||||
[[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel];
|
||||
}
|
||||
showToast(@"设置成功");
|
||||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||||
showToast(msg);
|
||||
}];
|
||||
}
|
||||
|
||||
-(UIButton *)commitBtn{
|
||||
if (!_commitBtn) {
|
||||
_commitBtn = [[UIButton alloc] init];
|
||||
_commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.view.height-NavContentHeight-44-kSafeAreaBottom-42-10, SCREEN_WIDTH-38*2, 42)];
|
||||
[_commitBtn setTitle:QXText(@"确认装扮") forState:(UIControlStateNormal)];
|
||||
[_commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
||||
[_commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
[_commitBtn addRoundedCornersWithRadius:21];
|
||||
_commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
_commitBtn.needEventInterval = 0.3;
|
||||
_commitBtn.backgroundColor = QXConfig.themeColor;
|
||||
}
|
||||
return _commitBtn;
|
||||
}
|
||||
-(UICollectionView *)collectionView{
|
||||
if (!_collectionView) {
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
layout.minimumLineSpacing = 22;
|
||||
layout.minimumInteritemSpacing = 22;
|
||||
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
|
||||
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.headerImageView.bottom+12+12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) collectionViewLayout:layout];
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.backgroundColor = [UIColor clearColor];
|
||||
[_collectionView registerNib:[UINib nibWithNibName:@"QXDressCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXDressCell"];
|
||||
}
|
||||
return _collectionView;
|
||||
}
|
||||
-(QXSeatHeaderView *)headerImageView{
|
||||
if (!_headerImageView) {
|
||||
_headerImageView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-104)/2, 24, 104, 104)];
|
||||
[_headerImageView setHeadIcon:[QXGlobal shareGlobal].loginModel.avatar dress:[QXGlobal shareGlobal].loginModel.dress];
|
||||
}
|
||||
return _headerImageView;
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user