更新 XPMineUserInfoHeaderView.m,调整勋章显示逻辑,允许最多显示 10 个勋章;在 UserRoomCardViewController.m 中新增 UserRoomCardMedalCell 以支持勋章的展示,优化勋章区域的高度计算和更新逻辑,保持代码结构一致性。

This commit is contained in:
edwinQQQ
2025-06-24 18:50:45 +08:00
parent c5d966317b
commit 1190e0f6d9
2 changed files with 285 additions and 19 deletions

View File

@@ -1693,7 +1693,7 @@ HWDMP4PlayDelegate>
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
// 10
NSInteger count = MIN(medals.count, 2);
NSInteger count = MIN(medals.count, 10);
for (NSInteger i = 0; i < count; i++) {
BaseModelVo *medal = medals[i];
UIView *medalContainer = [[UIView alloc] init];

View File

@@ -9,6 +9,7 @@
#import "XPUserCardPresenter.h"
#import "XPRoomGiftAnimationParser.h"
#import <UIImageView+WebCache.h>
#import "XPSendGiftView.h"
#import "XPRoomSendTextView.h"
@@ -419,6 +420,213 @@
@end
@interface UserRoomCardMedalCell : UICollectionViewCell
@property(nonatomic, strong) UserInfoModel *userInfo;
@property(nonatomic, strong) UIScrollView *medalsScrollView;
@property(nonatomic, strong) UIStackView *medalsStackView;
@property(nonatomic, strong) NSArray<VAPView *> *medalMP4Views;
@property(nonatomic, strong) MASConstraint *scrollViewWidthConstraint;
+ (void)registerTo:(UICollectionView *)collectionView;
+ (UserRoomCardMedalCell *)cellFor:(UICollectionView *)collectionView
indexPath:(NSIndexPath *)indexPath
userInfo:(UserInfoModel *)userInfo;
@end
@implementation UserRoomCardMedalCell
+ (void)registerTo:(UICollectionView *)collectionView {
[collectionView registerClass:[self class]
forCellWithReuseIdentifier:NSStringFromClass([self class])];
}
+ (UserRoomCardMedalCell *)cellFor:(UICollectionView *)collectionView
indexPath:(NSIndexPath *)indexPath
userInfo:(UserInfoModel *)userInfo {
UserRoomCardMedalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([self class])
forIndexPath:indexPath];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
cell.userInfo = userInfo;
return cell;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.medalsScrollView];
// ScrollView 5
CGFloat maxMedalsWidth = kGetScaleWidth(30) * 5 + 4 * 5; // 54
[self.medalsScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.centerY.mas_equalTo(self.contentView);
make.height.mas_equalTo(kGetScaleWidth(30));
//
self.scrollViewWidthConstraint = make.width.mas_equalTo(maxMedalsWidth);
//
make.leading.mas_greaterThanOrEqualTo(self.contentView).offset(15);
make.trailing.mas_lessThanOrEqualTo(self.contentView).offset(-15);
}];
[self.medalsScrollView addSubview:self.medalsStackView];
[self.medalsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.leading.mas_equalTo(self.medalsScrollView);
make.height.mas_equalTo(self.medalsScrollView);
// ScrollView
make.centerX.mas_equalTo(self.medalsScrollView).priority(UILayoutPriorityDefaultLow);
}];
}
return self;
}
- (void)setUserInfo:(UserInfoModel *)userInfo {
_userInfo = userInfo;
[self updateMedalsDisplay];
}
- (void)updateMedalsDisplay {
//
for (UIView *subview in self.medalsStackView.arrangedSubviews) {
[self.medalsStackView removeArrangedSubview:subview];
[subview removeFromSuperview];
}
// MP4
if (self.medalMP4Views) {
for (VAPView *mp4View in self.medalMP4Views) {
[mp4View stopHWDMP4];
}
}
NSArray *medals = self.userInfo.medalsPic;
if (medals.count == 0) {
self.medalsScrollView.hidden = YES;
return;
} else {
#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];
medals = arr.copy;
#endif
}
self.medalsScrollView.hidden = NO;
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
NSInteger count = medals.count; // 5
for (NSInteger i = 0; i < count; i++) {
BaseModelVo *medal = medals[i];
UIView *medalContainer = [[UIView alloc] init];
medalContainer.backgroundColor = [UIColor clearColor];
[self.medalsStackView addArrangedSubview:medalContainer];
[medalContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(30)).priority(UILayoutPriorityRequired);
}];
// picUrl MP4
if (![NSString isEmpty:medal.picUrl]) {
BOOL isMP4 = [[medal.picUrl.lowercaseString pathExtension] isEqualToString:@"mp4"];
if (isMP4) {
// MP4
VAPView *mp4View = [[VAPView alloc] init];
mp4View.contentMode = UIViewContentModeScaleAspectFit;
mp4View.userInteractionEnabled = NO;
[medalContainer addSubview:mp4View];
[mp4View mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(medalContainer);
}];
[mp4Views addObject:mp4View];
XPRoomGiftAnimationParser *parser = [[XPRoomGiftAnimationParser alloc] init];
[parser parseWithURL:medal.picUrl
completionBlock:^(NSString * _Nullable videoUrl) {
if (videoUrl.length > 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[mp4View setMute:YES];
[mp4View playHWDMP4:videoUrl repeatCount:-1 delegate:nil];
});
}
} failureBlock:nil];
} else {
//
NetImageView *imageView = [[NetImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.userInteractionEnabled = NO;
[medalContainer addSubview:imageView];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(medalContainer);
}];
[imageView loadImageWithUrl:medal.picUrl completion:nil fail:nil];
}
}
}
// ScrollView contentSize
dispatch_async(dispatch_get_main_queue(), ^{
[self.medalsStackView layoutIfNeeded];
CGFloat stackViewWidth = self.medalsStackView.frame.size.width;
if (stackViewWidth == 0) {
// StackView
CGFloat expectedWidth = count * kGetScaleWidth(30) + (count - 1) * 5;
stackViewWidth = expectedWidth;
}
// ScrollView 使使
CGFloat maxDisplayWidth = kGetScaleWidth(30) * 5 + 4 * 5; // 5
CGFloat scrollViewWidth = MIN(stackViewWidth, maxDisplayWidth);
// ScrollView
[self.scrollViewWidthConstraint uninstall];
[self.medalsScrollView mas_updateConstraints:^(MASConstraintMaker *make) {
self.scrollViewWidthConstraint = make.width.mas_equalTo(scrollViewWidth);
}];
self.medalsScrollView.contentSize = CGSizeMake(stackViewWidth, kGetScaleWidth(30));
[self.contentView layoutIfNeeded];
});
self.medalMP4Views = [mp4Views copy];
}
- (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];
_medalsStackView.backgroundColor = [UIColor clearColor];
_medalsStackView.axis = UILayoutConstraintAxisHorizontal;
_medalsStackView.distribution = UIStackViewDistributionFill;
_medalsStackView.alignment = UIStackViewAlignmentCenter;
_medalsStackView.spacing = 5;
}
return _medalsStackView;
}
@end
@interface UserRoomCardUserActionCell : UICollectionViewCell
@property(nonatomic, strong) UserInfoModel *userInfo;
@@ -1299,6 +1507,9 @@
#pragma mark -
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
#if DEBUG
// userInfo.medalsPic = @[];
#endif
self.userInfoModel = userInfo;
self.avatar.userInfo = userInfo;
@kWeakify(self);
@@ -1307,6 +1518,9 @@
[self gotoUserInfoVC];
}];
//
[self updateCollectionViewFrame];
[self.collectionView reloadData];
BOOL needLoadVIPbg = true;
@@ -1416,18 +1630,8 @@
self.micActions = temp;
[self reloadAllUI];
if (self.micActions.count == 0) {
self.collectionHeight = 120 + 30 + 60 + ([self configRoomDatingPickHeart] ? 68 : 0) + kSafeAreaBottomHeight;
} else {
self.collectionHeight = 120 + 30 + 60 + 66 + ([self configRoomDatingPickHeart] ? 68 : 0) + kSafeAreaBottomHeight;
}
CGFloat space_top = KScreenHeight - self.collectionHeight;
[UIView animateWithDuration:0.25 animations:^{
self.collectionView.frame = CGRectMake(0, space_top, KScreenWidth, self.collectionHeight);
} completion:^(BOOL finished) {
self.view.alpha = 1;
[XNDJTDDLoadingTool hideHUD];
}];
// micActions
[self updateCollectionViewFrame];
}
-(void)onGetFollowDataSccess{
@@ -1715,7 +1919,7 @@
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 4;
return 5;
}
- (CGSize)collectionView:(UICollectionView *)collectionView
@@ -1729,9 +1933,13 @@
return CGSizeMake(self.collectionViewWidth, 30);
break;
case 2:
return CGSizeMake(self.collectionViewWidth, 60);
return CGSizeMake(self.collectionViewWidth,
self.userInfoModel.medalsPic.count == 0 ? 0 : 40);
break;
case 3:
return CGSizeMake(self.collectionViewWidth, 60);
break;
case 4:
if (self.micActions.count > 0) {
return CGSizeMake(self.collectionViewWidth, 38 + 16 + 12 + ([self configRoomDatingPickHeart] ? 36 + 32 : 0));
} else {
@@ -1800,6 +2008,14 @@
}
break;
case 2: {
// Cell
UserRoomCardMedalCell *cell = [UserRoomCardMedalCell cellFor:collectionView
indexPath:indexPath
userInfo:self.userInfoModel];
return cell;
}
break;
case 3: {
@kWeakify(self);
UserRoomCardUserActionCell *cell = [UserRoomCardUserActionCell cellFor:collectionView
indexPath:indexPath
@@ -1812,7 +2028,7 @@
return cell;
}
break;
case 3: {
case 4: {
@kWeakify(self);
UserRoomCardMicActionCell *cell = [UserRoomCardMicActionCell cellFor:collectionView
indexPath:indexPath
@@ -1858,9 +2074,12 @@
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
self.collectionHeight = 120 + kSafeAreaBottomHeight + 30 + ([self configRoomDatingPickHeart] ? 68 : 0) + kSafeAreaBottomHeight;
// 使
self.collectionHeight = [self calculateCollectionViewHeight];
CGFloat space_top = KScreenHeight - self.collectionHeight;
self.collectionViewWidth = KScreenWidth;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,
space_top,
KScreenWidth,
@@ -1879,10 +2098,9 @@
_collectionView.clipsToBounds = NO;
[UserRoomCardInfoCell registerTo:_collectionView];
[UserRoomCardNameplateCell registerTo:_collectionView];
[UserRoomCardMedalCell registerTo:_collectionView];
[UserRoomCardUserActionCell registerTo:_collectionView];
[UserRoomCardMicActionCell registerTo:_collectionView];
// _collectionView.hidden = YES;
}
return _collectionView;
}
@@ -1922,4 +2140,52 @@
return _avatar;
}
#pragma mark - Height Calculation
- (CGFloat)calculateCollectionViewHeight {
//
// Cell 0 (): 120
// Cell 1 (): 30
// Cell 2 (): 040
// Cell 3 (): 60
// Cell 4 (): 066
// : 680
// : kSafeAreaBottomHeight
CGFloat baseHeight = 120 + 30 + 60; //
//
CGFloat medalHeight = 0;
if (self.userInfoModel && self.userInfoModel.medalsPic.count > 0) {
medalHeight = 40;
}
//
CGFloat micActionHeight = 0;
if (self.micActions.count > 0) {
micActionHeight = 66;
}
//
CGFloat datingHeight = [self configRoomDatingPickHeart] ? 68 : 0;
return baseHeight + medalHeight + micActionHeight + datingHeight + kSafeAreaBottomHeight;
}
- (void)updateCollectionViewFrame {
CGFloat newHeight = [self calculateCollectionViewHeight];
if (ABS(self.collectionHeight - newHeight) > 0.1) { //
self.collectionHeight = newHeight;
CGFloat space_top = KScreenHeight - self.collectionHeight;
[UIView animateWithDuration:0.25 animations:^{
self.collectionView.frame = CGRectMake(0, space_top, KScreenWidth, self.collectionHeight);
} completion:^(BOOL finished) {
if (self.userInfoModel) { //
self.view.alpha = 1;
[XNDJTDDLoadingTool hideHUD];
}
}];
}
}
@end