更新 XPMineUserInfoHeaderView.m,新增 UIScrollView 作为勋章展示的容器,调整勋章 StackView 的布局逻辑以适应 ScrollView,更新勋章显示方法以处理勋章的内容尺寸,保持代码结构一致性。
This commit is contained in:
@@ -172,6 +172,7 @@ HWDMP4PlayDelegate>
|
||||
@property (nonatomic, strong) VAPView *personalBGMP4;
|
||||
@property (nonatomic, strong) SVGAImageView *personalBGSvga;
|
||||
|
||||
@property (nonatomic, strong) UIScrollView *medalsScrollView;
|
||||
@property (nonatomic, strong) UIStackView *medalsStackView;
|
||||
|
||||
@property (nonatomic, strong) NSArray<VAPView *> *medalMP4Views;
|
||||
@@ -536,16 +537,24 @@ HWDMP4PlayDelegate>
|
||||
}
|
||||
|
||||
- (void)setupMedalsArea {
|
||||
[self.userInfoView addSubview:self.medalsStackView];
|
||||
[self.medalsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// 添加 ScrollView 作为容器
|
||||
[self.userInfoView addSubview:self.medalsScrollView];
|
||||
[self.medalsScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.nameplateCollectionView.mas_bottom).offset(6);
|
||||
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
|
||||
// make.trailing.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(-15));
|
||||
make.height.mas_equalTo(30);
|
||||
make.trailing.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(-15));
|
||||
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 {
|
||||
@@ -553,7 +562,7 @@ HWDMP4PlayDelegate>
|
||||
[self.locateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
|
||||
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;
|
||||
}
|
||||
|
||||
- (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 {
|
||||
if (!_medalsStackView) {
|
||||
_medalsStackView = [[UIStackView alloc] init];
|
||||
@@ -1663,15 +1685,15 @@ HWDMP4PlayDelegate>
|
||||
}
|
||||
|
||||
if (medals.count == 0) {
|
||||
self.medalsStackView.hidden = YES;
|
||||
self.medalsScrollView.hidden = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
self.medalsStackView.hidden = NO;
|
||||
self.medalsScrollView.hidden = NO;
|
||||
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
|
||||
|
||||
// 最多显示 10 个勋章
|
||||
NSInteger count = MIN(medals.count, 10);
|
||||
NSInteger count = MIN(medals.count, 2);
|
||||
for (NSInteger i = 0; i < count; i++) {
|
||||
BaseModelVo *medal = medals[i];
|
||||
UIView *medalContainer = [[UIView alloc] init];
|
||||
@@ -1718,7 +1740,9 @@ HWDMP4PlayDelegate>
|
||||
|
||||
[self.medalsStackView addArrangedSubview:medalContainer];
|
||||
[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];
|
||||
}
|
||||
|
||||
// 更新 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];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user