删除不再使用的资源文件,包括多个图像集和其对应的 Contents.json 文件,更新 MedalsModel.h 和 MedalsModel.m 以支持使用勋章的类型,新增 MedalsCyclePagerCell 组件以优化勋章展示,保持代码结构一致性。
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#import "UserInfoModel.h"
|
||||
#import "TYCyclePagerView.h"
|
||||
#import "MedalsCollectionViewCell.h"
|
||||
#import "MedalsCyclePagerCell.h"
|
||||
#import "MedalsDetailView.h"
|
||||
#import "MedalsWearingViewController.h"
|
||||
#import "MedalsRankViewController.h"
|
||||
@@ -28,18 +29,20 @@ typedef enum : NSInteger {
|
||||
MedalsCenterDisplayType_Square
|
||||
} MedalsCenterDisplayType;
|
||||
|
||||
@interface MedalsViewController () <MedalsPresenterProtocol, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||
@interface MedalsViewController () <MedalsPresenterProtocol, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, TYCyclePagerViewDataSource, TYCyclePagerViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) UserInfoModel *userInfo;
|
||||
@property (nonatomic, copy) NSArray <UIButton *> *centerTabButtons;
|
||||
@property (nonatomic, strong) UILabel *medalDescLabel;
|
||||
@property (nonatomic, strong) UIButton *emptyUserMedalButton;
|
||||
@property (nonatomic, strong) TYCyclePagerView *medalsCyclePagerView;
|
||||
@property (nonatomic, strong) UIView *emptyView;
|
||||
@property (nonatomic, copy) UICollectionView *medalsCollectionView;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceTaskMedals;
|
||||
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceActivityMedals;
|
||||
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceGloryMedals;
|
||||
@property (nonatomic, copy) NSArray <MedalVo *> *useMedals;
|
||||
|
||||
@property (nonatomic, assign) NSInteger currentPageTaskMedals;
|
||||
@property (nonatomic, assign) NSInteger currentPageActivityMedals;
|
||||
@@ -110,6 +113,8 @@ typedef enum : NSInteger {
|
||||
[self setupWearingButton];
|
||||
if (self.userInfo.medals.medalCount == 0) {
|
||||
[self setupEmptyUserMedals];
|
||||
} else {
|
||||
[self setupWearingUserMedals];
|
||||
}
|
||||
} else {
|
||||
[self setupOthersMedalInfo];
|
||||
@@ -265,11 +270,19 @@ typedef enum : NSInteger {
|
||||
}
|
||||
|
||||
- (void)setupEmptyUserMedals {
|
||||
|
||||
[self.view addSubview:self.medalsCyclePagerView];
|
||||
[self.view addSubview:self.emptyUserMedalButton];
|
||||
[self.emptyUserMedalButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(100);
|
||||
make.width.height.mas_equalTo(184);
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.size.mas_equalTo(CGSizeMake(184, 184));
|
||||
make.top.mas_equalTo(100);
|
||||
}];
|
||||
|
||||
[self.medalsCyclePagerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.emptyUserMedalButton);
|
||||
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width);
|
||||
make.height.mas_equalTo(self.emptyUserMedalButton);
|
||||
}];
|
||||
|
||||
[self.view addSubview:self.medalDescLabel];
|
||||
@@ -282,6 +295,15 @@ typedef enum : NSInteger {
|
||||
}
|
||||
|
||||
- (void)setupWearingUserMedals {
|
||||
// 添加 TYCyclePagerView 用于显示佩戴的勋章
|
||||
[self.view addSubview:self.medalsCyclePagerView];
|
||||
[self.medalsCyclePagerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(100);
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width);
|
||||
make.height.mas_equalTo(184);
|
||||
}];
|
||||
|
||||
[self.view addSubview:self.medalDescLabel];
|
||||
self.medalDescLabel.text = @"显示过期时间";//YMLocalizedString(@"20.20.61_text_6");
|
||||
[self.medalDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -403,6 +425,7 @@ typedef enum : NSInteger {
|
||||
[self endReresh];
|
||||
[self _updateDataSource:userMedalsModel.medalSeries];
|
||||
[self _updateOtherInfo:userMedalsModel];
|
||||
[self _updateWearingInfo];
|
||||
}
|
||||
|
||||
- (void)userMedalsFailure {
|
||||
@@ -463,8 +486,15 @@ typedef enum : NSInteger {
|
||||
}
|
||||
|
||||
- (void)_updateWearingInfo {
|
||||
self.useMedals = self.userMedalsModel.useMedals;
|
||||
if (self.displayType != MedalsCenterDisplayType_Other) {
|
||||
|
||||
if (self.useMedals.count > 0 ) {
|
||||
self.emptyUserMedalButton.hidden = YES;
|
||||
[self.medalsCyclePagerView reloadData];
|
||||
} else {
|
||||
self.emptyUserMedalButton.hidden = NO;
|
||||
self.medalsCyclePagerView.hidden = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,6 +642,50 @@ typedef enum : NSInteger {
|
||||
return model;
|
||||
}
|
||||
|
||||
#pragma mark - TYCyclePagerView DataSource & Delegate
|
||||
|
||||
- (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
|
||||
return self.useMedals.count;
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
|
||||
MedalsCyclePagerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"MedalsCyclePagerCell" forIndex:index];
|
||||
MedalVo *vo = [self.useMedals xpSafeObjectAtIndex:index];
|
||||
[cell updateCell:vo];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
|
||||
TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc] init];
|
||||
layout.itemSize = CGSizeMake(184, 184);
|
||||
layout.itemSpacing = 10;
|
||||
layout.layoutType = TYCyclePagerTransformLayoutLinear;
|
||||
layout.itemHorizontalCenter = YES;
|
||||
return layout;
|
||||
}
|
||||
|
||||
- (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
|
||||
// 处理滚动事件,暂停之前的 cell,恢复当前的 cell
|
||||
// 获取可见的 cells
|
||||
NSArray *visibleCells = pageView.collectionView.visibleCells;
|
||||
|
||||
// 简化处理:遍历所有可见的 cells,暂停非当前 index 的 cell
|
||||
for (UICollectionViewCell *cell in visibleCells) {
|
||||
if ([cell isKindOfClass:[MedalsCyclePagerCell class]]) {
|
||||
NSIndexPath *indexPath = [pageView.collectionView indexPathForCell:cell];
|
||||
if (indexPath) {
|
||||
NSInteger cellIndex = indexPath.item;
|
||||
if (cellIndex == toIndex) {
|
||||
[(MedalsCyclePagerCell *)cell willDisplay];
|
||||
} else {
|
||||
[(MedalsCyclePagerCell *)cell didEndDisplaying];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy load
|
||||
- (UIButton *)medalsSquareButton {
|
||||
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
@@ -767,4 +841,18 @@ typedef enum : NSInteger {
|
||||
return _otherAvatar;
|
||||
}
|
||||
|
||||
- (TYCyclePagerView *)medalsCyclePagerView {
|
||||
if (!_medalsCyclePagerView) {
|
||||
_medalsCyclePagerView = [[TYCyclePagerView alloc] init];
|
||||
_medalsCyclePagerView.dataSource = self;
|
||||
_medalsCyclePagerView.delegate = self;
|
||||
_medalsCyclePagerView.backgroundColor = [UIColor clearColor];
|
||||
_medalsCyclePagerView.isInfiniteLoop = NO;
|
||||
_medalsCyclePagerView.clipsToBounds = NO;
|
||||
[_medalsCyclePagerView registerClass:[MedalsCyclePagerCell class]
|
||||
forCellWithReuseIdentifier:@"MedalsCyclePagerCell"];
|
||||
}
|
||||
return _medalsCyclePagerView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user