更新 MedalsViewController.m,新增其他用户勋章的显示逻辑,包括 MP4 播放和图片展示,优化相关方法以提升用户体验,保持代码结构一致性。同时,更新 MedalsWearingControlCollectionViewCell.m,移除调试背景颜色设置,保持代码整洁。

This commit is contained in:
edwinQQQ
2025-06-24 15:01:33 +08:00
parent a15d6b34ed
commit 059305d3df
2 changed files with 110 additions and 8 deletions

View File

@@ -61,6 +61,7 @@ typedef enum : NSInteger {
@property (nonatomic, strong) XPRoomGiftAnimationParser *mp4Parser;
@property (nonatomic, strong) UILabel *otherNameLabel;
@property (nonatomic, strong) UILabel *otherCountLabel;
@property (nonatomic, strong) UserMedalsModel *otherMedalsModel;
//
@property (nonatomic, strong) NSTimer *autoScrollTimer;
@@ -106,6 +107,7 @@ typedef enum : NSInteger {
- (void)dealloc {
[self stopAutoScroll];
[self stopOtherMedalMP4Playback];
}
- (void)viewDidLoad {
@@ -142,6 +144,9 @@ typedef enum : NSInteger {
//
[self stopAutoScroll];
// MP4
[self stopOtherMedalMP4Playback];
}
- (void)stopAllCellsPlayback {
@@ -344,6 +349,13 @@ typedef enum : NSInteger {
make.trailing.mas_equalTo(bg).offset(-15);
make.size.mas_equalTo(CGSizeMake(80, 80));
}];
[self.view addSubview:self.otherMP4View];
[self.otherMP4View mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(bg);
make.trailing.mas_equalTo(bg).offset(-15);
make.size.mas_equalTo(CGSizeMake(80, 80));
}];
}
- (void)setupCenterTabs {
@@ -691,10 +703,99 @@ typedef enum : NSInteger {
}
- (void)_updateOtherInfo:(UserMedalsModel *)userModel {
_otherMedalsModel = userModel;
if (self.displayType == MedalsCenterDisplayType_Other) {
self.otherAvatar.imageUrl = userModel.avatar;
self.otherNameLabel.text = userModel.nick;
self.otherCountLabel.text = @(userModel.medalNum).stringValue;
MedalVo *useMedal = [[userModel useMedals] xpSafeObjectAtIndex:0];
#if DEBUG
useMedal = [[MedalVo alloc] init];
useMedal.picUrl = @"https://image.pekolive.com/V1.mp4";
#endif
if (useMedal) {
if ([useMedal.picUrl hasSuffix:@"mp4"]) {
// MP4
[self displayOtherMedalMp4:useMedal.picUrl];
} else {
//
[self displayOtherMedalImage:useMedal.picUrl];
}
} else {
//
[self displayOtherMedalImage:nil];
}
}
}
#pragma mark -
/**
*
* @param imageUrl URLnil
*/
- (void)displayOtherMedalImage:(NSString *)imageUrl {
// MP4
[self stopOtherMedalMP4Playback];
// MP4
self.otherMP4View.hidden = YES;
self.otherMedal.hidden = NO;
if (imageUrl && imageUrl.length > 0) {
self.otherMedal.imageUrl = imageUrl;
} else {
//
self.otherMedal.image = kImage(@"medals_empty");
}
}
/**
* MP4
* @param mp4Url MP4URL
*/
- (void)displayOtherMedalMp4:(NSString *)mp4Url {
if (!mp4Url || mp4Url.length == 0) {
[self displayOtherMedalImage:nil];
return;
}
// MP4
[self stopOtherMedalMP4Playback];
// MP4
self.otherMP4View.hidden = NO;
self.otherMedal.hidden = YES;
// MP4
if (!self.mp4Parser) {
self.mp4Parser = [[XPRoomGiftAnimationParser alloc] init];
}
@kWeakify(self);
[self.mp4Parser parseWithURL:mp4Url
completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(self);
if (![NSString isEmpty:videoUrl] && !self.otherMP4View.hidden) {
//
[self.otherMP4View setMute:YES];
[self.otherMP4View playHWDMP4:videoUrl repeatCount:-1 delegate:nil];
}
} failureBlock:^(NSError * _Nullable error) {
@kStrongify(self);
NSLog(@"Failed to parse other user medal mp4: %@", error);
//
[self displayOtherMedalImage:nil];
}];
}
/**
* MP4
*/
- (void)stopOtherMedalMP4Playback {
if (self.otherMP4View) {
[self.otherMP4View stopHWDMP4];
}
}
@@ -1049,7 +1150,7 @@ typedef enum : NSInteger {
_medalsCyclePagerView = [[TYCyclePagerView alloc] init];
_medalsCyclePagerView.dataSource = self;
_medalsCyclePagerView.delegate = self;
_medalsCyclePagerView.backgroundColor = [UIColor redColor];//[UIColor clearColor];
_medalsCyclePagerView.backgroundColor = [UIColor clearColor];
_medalsCyclePagerView.isInfiniteLoop = NO;
_medalsCyclePagerView.clipsToBounds = NO;
// _medalsCyclePagerView.autoScrollInterval = 0; //
@@ -1062,4 +1163,12 @@ typedef enum : NSInteger {
return _medalsCyclePagerView;
}
- (VAPView *)otherMP4View {
if (!_otherMP4View) {
_otherMP4View = [[VAPView alloc] init];
_otherMP4View.contentMode = UIViewContentModeScaleAspectFit;
}
return _otherMP4View;
}
@end

View File

@@ -86,18 +86,11 @@
- (void)updateMedal:(MedalVo *)medalVo {
if (!medalVo) {
self.medalImageView.imageUrl = @"";
#if DEBUG
self.medalImageView.backgroundColor = [UIColor clearColor];
#endif
return;
}
if (![medalVo.picUrl hasSuffix:@"mp4"]) {
self.medalImageView.imageUrl = medalVo.picUrl;
}
#if DEBUG
self.medalImageView.backgroundColor = [UIColor redColor];
#endif
}
- (instancetype)initWithFrame:(CGRect)frame