更新 XPMineUserInfoHeaderView.m,新增 UIScrollView 作为勋章展示的容器,调整勋章 StackView 的布局逻辑以适应 ScrollView,更新勋章显示方法以处理勋章的内容尺寸,保持代码结构一致性。

This commit is contained in:
edwinQQQ
2025-06-24 17:10:11 +08:00
parent 6573c0f6fe
commit c5d966317b

View File

@@ -172,6 +172,7 @@ HWDMP4PlayDelegate>
@property (nonatomic, strong) VAPView *personalBGMP4; @property (nonatomic, strong) VAPView *personalBGMP4;
@property (nonatomic, strong) SVGAImageView *personalBGSvga; @property (nonatomic, strong) SVGAImageView *personalBGSvga;
@property (nonatomic, strong) UIScrollView *medalsScrollView;
@property (nonatomic, strong) UIStackView *medalsStackView; @property (nonatomic, strong) UIStackView *medalsStackView;
@property (nonatomic, strong) NSArray<VAPView *> *medalMP4Views; @property (nonatomic, strong) NSArray<VAPView *> *medalMP4Views;
@@ -536,16 +537,24 @@ HWDMP4PlayDelegate>
} }
- (void)setupMedalsArea { - (void)setupMedalsArea {
[self.userInfoView addSubview:self.medalsStackView]; // ScrollView
[self.medalsStackView mas_makeConstraints:^(MASConstraintMaker *make) { [self.userInfoView addSubview:self.medalsScrollView];
[self.medalsScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.nameplateCollectionView.mas_bottom).offset(6); make.top.mas_equalTo(self.nameplateCollectionView.mas_bottom).offset(6);
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15)); make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
// make.trailing.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(-15)); make.trailing.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(-15));
make.height.mas_equalTo(30); make.height.mas_equalTo(kGetScaleWidth(30));
}];
// ScrollView StackView
[self.medalsScrollView addSubview:self.medalsStackView];
[self.medalsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.medalsScrollView);
make.height.mas_equalTo(self.medalsScrollView);
}]; }];
// //
self.medalsStackView.hidden = YES; self.medalsScrollView.hidden = YES;
} }
- (void)setupLocateArea { - (void)setupLocateArea {
@@ -553,7 +562,7 @@ HWDMP4PlayDelegate>
[self.locateLabel mas_makeConstraints:^(MASConstraintMaker *make) { [self.locateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15)); make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
make.height.mas_equalTo(18); make.height.mas_equalTo(18);
make.top.mas_equalTo(self.medalsStackView.mas_bottom).offset(6); make.top.mas_equalTo(self.medalsScrollView.mas_bottom).offset(6);
}]; }];
} }
@@ -1621,6 +1630,19 @@ HWDMP4PlayDelegate>
return _personalBGImageView; return _personalBGImageView;
} }
- (UIScrollView *)medalsScrollView {
if (!_medalsScrollView) {
_medalsScrollView = [[UIScrollView alloc] init];
_medalsScrollView.backgroundColor = [UIColor clearColor];
_medalsScrollView.showsHorizontalScrollIndicator = NO;
_medalsScrollView.showsVerticalScrollIndicator = NO;
_medalsScrollView.scrollEnabled = YES;
_medalsScrollView.bounces = YES;
_medalsScrollView.alwaysBounceHorizontal = NO;
}
return _medalsScrollView;
}
- (UIStackView *)medalsStackView { - (UIStackView *)medalsStackView {
if (!_medalsStackView) { if (!_medalsStackView) {
_medalsStackView = [[UIStackView alloc] init]; _medalsStackView = [[UIStackView alloc] init];
@@ -1663,15 +1685,15 @@ HWDMP4PlayDelegate>
} }
if (medals.count == 0) { if (medals.count == 0) {
self.medalsStackView.hidden = YES; self.medalsScrollView.hidden = YES;
return; return;
} }
self.medalsStackView.hidden = NO; self.medalsScrollView.hidden = NO;
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array]; NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
// 10 // 10
NSInteger count = MIN(medals.count, 10); NSInteger count = MIN(medals.count, 2);
for (NSInteger i = 0; i < count; i++) { for (NSInteger i = 0; i < count; i++) {
BaseModelVo *medal = medals[i]; BaseModelVo *medal = medals[i];
UIView *medalContainer = [[UIView alloc] init]; UIView *medalContainer = [[UIView alloc] init];
@@ -1718,7 +1740,9 @@ HWDMP4PlayDelegate>
[self.medalsStackView addArrangedSubview:medalContainer]; [self.medalsStackView addArrangedSubview:medalContainer];
[medalContainer mas_makeConstraints:^(MASConstraintMaker *make) { [medalContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(30).priority(UILayoutPriorityRequired); make.width.height
.mas_equalTo(kGetScaleWidth(30))
.priority(UILayoutPriorityRequired);
}]; }];
// //
@@ -1730,6 +1754,16 @@ HWDMP4PlayDelegate>
[medalContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; [medalContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
} }
// ScrollView contentSize
[self.medalsStackView layoutIfNeeded];
CGFloat stackViewWidth = self.medalsStackView.frame.size.width;
if (stackViewWidth == 0) {
// StackView
CGFloat expectedWidth = count * kGetScaleWidth(30) + (count - 1) * 5;
stackViewWidth = expectedWidth;
}
self.medalsScrollView.contentSize = CGSizeMake(stackViewWidth, kGetScaleWidth(30));
self.medalMP4Views = [mp4Views copy]; self.medalMP4Views = [mp4Views copy];
} }