更新 XPMineUserInfoHeaderView.m,新增 medalsStackView 和 medalMP4Views 属性以支持勋章展示逻辑;添加 medalsHeight 方法计算勋章高度;实现 setupMedalsArea 方法以配置勋章视图;更新 updateMedalsDisplay 方法以处理勋章的 MP4 和图片展示,保持代码结构一致性。同时,更新 .vscode/settings.json 文件以添加拼写检查词汇。
This commit is contained in:
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@@ -9,16 +9,29 @@
|
||||
"cSpell.words": [
|
||||
"autoreleasepool",
|
||||
"Autoresizing",
|
||||
"BGMP",
|
||||
"Bugly",
|
||||
"Commont",
|
||||
"Contol",
|
||||
"CPSVGA",
|
||||
"erban",
|
||||
"exper",
|
||||
"Headwear",
|
||||
"HWDMP",
|
||||
"Interitem",
|
||||
"kindof",
|
||||
"MSRTL",
|
||||
"NIMSDK",
|
||||
"Nonnull",
|
||||
"NSEC",
|
||||
"NSURL",
|
||||
"Offical",
|
||||
"Procotol",
|
||||
"QGVAP",
|
||||
"Subview",
|
||||
"subviews",
|
||||
"Superview",
|
||||
"Uids"
|
||||
"Uids",
|
||||
"XNDJTDD"
|
||||
]
|
||||
}
|
@@ -173,7 +173,8 @@ HWDMP4PlayDelegate>
|
||||
@property (nonatomic, strong) SVGAImageView *personalBGSvga;
|
||||
|
||||
@property (nonatomic, strong) UIStackView *medalsStackView;
|
||||
@property (nonatomic, copy) NSArray <BaseModelVo *> *userMedals;
|
||||
|
||||
@property (nonatomic, strong) NSArray<VAPView *> *medalMP4Views;
|
||||
|
||||
@end
|
||||
|
||||
@@ -217,6 +218,14 @@ HWDMP4PlayDelegate>
|
||||
return namePlateHeight;
|
||||
}
|
||||
|
||||
+ (CGFloat)medalsHeight:(NSArray *)medalsList {
|
||||
if (medalsList.count > 0) {
|
||||
// 勋章高度 30px + 上下间距 12px (6px * 2)
|
||||
return 30 + 12;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ (CGFloat)headerHeight:(UserInfoModel *)model cps:(NSInteger)cps {
|
||||
CGFloat height = 0;
|
||||
NSInteger numberOfLines = 1;
|
||||
@@ -241,8 +250,8 @@ HWDMP4PlayDelegate>
|
||||
numberOfLines = ceil(textRect.size.height / lineHeight);
|
||||
}
|
||||
|
||||
// topAlbum + cp + name plate area + line contents + others
|
||||
height = kGetScaleWidth(195) + 160 + [self namePlateHeight:model.userNameplateList] + (lineHeight * numberOfLines) + kGetScaleWidth(80);
|
||||
// topAlbum + cp + name plate area + medals area + line contents + others
|
||||
height = kGetScaleWidth(195) + 160 + [self namePlateHeight:model.userNameplateList] + [self medalsHeight:model.medalsPic] + (lineHeight * numberOfLines) + kGetScaleWidth(80);
|
||||
if (cps == 0) {
|
||||
cps = 1;
|
||||
}
|
||||
@@ -289,6 +298,8 @@ HWDMP4PlayDelegate>
|
||||
|
||||
[self setupNameplateArea];
|
||||
|
||||
[self setupMedalsArea];
|
||||
|
||||
[self setupLocateArea];
|
||||
|
||||
[self setupCustomDesc];
|
||||
@@ -524,12 +535,25 @@ HWDMP4PlayDelegate>
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setupMedalsArea {
|
||||
[self.userInfoView addSubview:self.medalsStackView];
|
||||
[self.medalsStackView 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);
|
||||
}];
|
||||
|
||||
// 默认隐藏,有数据时再显示
|
||||
self.medalsStackView.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)setupLocateArea {
|
||||
[self.userInfoView addSubview:self.locateLabel];
|
||||
[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.nameplateCollectionView.mas_bottom).offset(6);
|
||||
make.top.mas_equalTo(self.medalsStackView.mas_bottom).offset(6);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -870,6 +894,9 @@ HWDMP4PlayDelegate>
|
||||
} else {
|
||||
self.nobleImageView.hidden = YES;
|
||||
}
|
||||
|
||||
// 更新勋章显示
|
||||
[self updateMedalsDisplay:userInfo.medalsPic];
|
||||
}
|
||||
|
||||
- (void)loadNamePlate:(NSString *)imagePath targetView:(NetImageView *)targetView {
|
||||
@@ -1594,4 +1621,127 @@ HWDMP4PlayDelegate>
|
||||
return _personalBGImageView;
|
||||
}
|
||||
|
||||
- (UIStackView *)medalsStackView {
|
||||
if (!_medalsStackView) {
|
||||
_medalsStackView = [[UIStackView alloc] init];
|
||||
_medalsStackView.backgroundColor = [UIColor clearColor];
|
||||
_medalsStackView.axis = UILayoutConstraintAxisHorizontal;
|
||||
_medalsStackView.distribution = UIStackViewDistributionEqualSpacing;
|
||||
_medalsStackView.alignment = UIStackViewAlignmentCenter;
|
||||
_medalsStackView.spacing = 5;
|
||||
}
|
||||
return _medalsStackView;
|
||||
}
|
||||
|
||||
- (NSArray<VAPView *> *)medalMP4Views {
|
||||
if (!_medalMP4Views) {
|
||||
_medalMP4Views = [NSArray array];
|
||||
}
|
||||
return _medalMP4Views;
|
||||
}
|
||||
|
||||
- (void)updateMedalsDisplay:(NSArray<BaseModelVo *> *)medals {
|
||||
#if DEBUG
|
||||
NSMutableArray *arr = [NSMutableArray arrayWithArray:medals];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
[arr addObjectsFromArray:arr.copy];
|
||||
medals = arr.copy;
|
||||
#endif
|
||||
// 停止并清除之前的播放器
|
||||
for (VAPView *mp4View in self.medalMP4Views) {
|
||||
[mp4View stopHWDMP4];
|
||||
}
|
||||
|
||||
// 清空 StackView 中的所有子视图
|
||||
for (UIView *subview in self.medalsStackView.arrangedSubviews) {
|
||||
[self.medalsStackView removeArrangedSubview:subview];
|
||||
[subview removeFromSuperview];
|
||||
}
|
||||
|
||||
if (medals.count == 0) {
|
||||
self.medalsStackView.hidden = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
self.medalsStackView.hidden = NO;
|
||||
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
|
||||
|
||||
// 最多显示 10 个勋章
|
||||
NSInteger count = MIN(medals.count, 10);
|
||||
for (NSInteger i = 0; i < count; i++) {
|
||||
BaseModelVo *medal = medals[i];
|
||||
UIView *medalContainer = [[UIView alloc] init];
|
||||
medalContainer.backgroundColor = [UIColor clearColor];
|
||||
|
||||
if ([medal.picUrl.lowercaseString hasSuffix:@".mp4"]) {
|
||||
// 显示 MP4 - 需要先通过 XPRoomGiftAnimationParser 解析
|
||||
VAPView *mp4View = [[VAPView alloc] init];
|
||||
mp4View.contentMode = UIViewContentModeScaleAspectFit;
|
||||
mp4View.hwd_Delegate = self;
|
||||
|
||||
[medalContainer addSubview:mp4View];
|
||||
[mp4View mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(medalContainer);
|
||||
}];
|
||||
|
||||
[mp4Views addObject:mp4View];
|
||||
|
||||
// 创建 parser 来解析 MP4 URL
|
||||
XPRoomGiftAnimationParser *parser = [[XPRoomGiftAnimationParser alloc] init];
|
||||
@kWeakify(self);
|
||||
[parser parseWithURL:[medal.picUrl pureURLString]
|
||||
completionBlock:^(NSString * _Nullable videoUrl) {
|
||||
@kStrongify(self);
|
||||
if (videoUrl.length) {
|
||||
[mp4View setMute:YES];
|
||||
[mp4View playHWDMP4:videoUrl repeatCount:-1 delegate:self];
|
||||
}
|
||||
} failureBlock:^(NSError * _Nullable error) {
|
||||
// 解析失败,可以显示默认图片或隐藏
|
||||
NSLog(@"Medal MP4 parse failed: %@", error);
|
||||
}];
|
||||
} else {
|
||||
// 显示图片
|
||||
NetImageView *imageView = [[NetImageView alloc] init];
|
||||
imageView.imageUrl = medal.picUrl;
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
|
||||
[medalContainer addSubview:imageView];
|
||||
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(medalContainer);
|
||||
}];
|
||||
}
|
||||
|
||||
[self.medalsStackView addArrangedSubview:medalContainer];
|
||||
[medalContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(30).priority(UILayoutPriorityRequired);
|
||||
}];
|
||||
|
||||
// 设置内容压缩阻力优先级,防止被压缩
|
||||
[medalContainer setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
||||
[medalContainer setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
||||
|
||||
// 设置内容拥抱优先级,防止被拉伸
|
||||
[medalContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
||||
[medalContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
||||
}
|
||||
|
||||
self.medalMP4Views = [mp4Views copy];
|
||||
}
|
||||
|
||||
- (void)stopAllMedalsMP4 {
|
||||
for (VAPView *mp4View in self.medalMP4Views) {
|
||||
[mp4View stopHWDMP4];
|
||||
}
|
||||
self.medalMP4Views = @[];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stopAllMedalsMP4];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user