Files
peko-ios/YuMi/Modules/YMMine/View/SubViews/MineInfo/XPMineUserInfoHeaderView.m

1782 lines
66 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPMineHeaderView.m
// xplan-ios
//
// Created by 冯硕 on 2021/9/22.
//
#import "XPMineUserInfoHeaderView.h"
///Third
#import <Masonry/Masonry.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "SDPhotoBrowser.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import <SVGA.h>
#import <YYImage/YYAnimatedImageView.h>
#import "UIView+VAP.h"
#import "XPRoomGiftAnimationParser.h"
///Tool
#import "UIImage+ImageEffects.h"
#import "UIImage+Utils.h"
#import "NetImageView.h"
#import "XPSkillCardPlayerManager.h"
#import "XPRoomMiniManager.h"
#import "SpriteSheetImageManager.h"
#import "XCCurrentVCStackManager.h"
///view
#import "CPCard.h"
#import "XPBeautIDView.h"
#import "CPListViewController.h"
///Model
#import "UserInfoModel.h"
@interface NameplateCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) NetImageView *imageView;
- (void)updateCell:(NameplateModel *)model;
@end
@implementation NameplateCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
return self;
}
- (void)updateCell:(NameplateModel *)model {
self.imageView.imageUrl = model.nameplateImage;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel labelInitWithText:@"" font:kFontRegular(10) textColor:[UIColor whiteColor]];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (NetImageView *)imageView {
if (!_imageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.imageType = ImageTypeUserCardLevel;
_imageView = [[NetImageView alloc] initWithConfig:config];
_imageView.userInteractionEnabled = YES;
_imageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _imageView;
}
@end
@interface XPMineUserInfoHeaderView ()<
SDCycleScrollViewDelegate,
SDPhotoBrowserDelegate,
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout,
HWDMP4PlayDelegate>
///轮播图
@property (nonatomic,strong) SDCycleScrollView *pi_cycleScrollView;
///显示当前的页数
@property (nonatomic,strong) UIButton *pageButton;
///审核中图标
@property (nonatomic,strong) UIImageView *reviewIcon;
///图片数组
@property (nonatomic,strong) NSArray *imageUrls;
///用户的头像和相册
@property (nonatomic,strong) NSMutableArray<UserPhoto *> *userPhotoArray;
///用户信息
@property (nonatomic,strong) UIView * userInfoView;
///头像的
@property (nonatomic,strong) UserPhoto *avatarPhoto;
///头像
@property (nonatomic,strong) NetImageView * avatarView;
@property (nonatomic,strong) NetImageView * avatarView_cp;
///普通的
@property (nonatomic,strong) YYAnimatedImageView *headWearImageView;
///头饰播放
@property (nonatomic, strong) SpriteSheetImageManager *manager;
@property (nonatomic, strong) SVGAImageView *headWearSvgaImageView;
@property (nonatomic, strong) SVGAImageView *headWearSvgaImageView_cp_me;
@property (nonatomic, strong) SVGAImageView *headWearSvgaImageView_cp;
@property (nonatomic, strong) UIImageView *cpAvatarHeart;
@property (nonatomic, strong) UIImageView *cpAvatarFlag;
///用户信息的背景
@property (nonatomic,strong) UIStackView *nickStackView;
///名字
@property (nonatomic,strong) UILabel *nameLabel;
///sex
@property (nonatomic,strong) UIButton *sexImageView;
///正在直播icon图
@property (nonatomic,strong) SVGAImageView *onlineIconView;
///正在直播中
@property (nonatomic,strong) UIButton *onlineButton;
@property(nonatomic, strong) UIStackView *stack;
///id
@property (nonatomic,strong) UILabel *idLabel;
@property (nonatomic, strong) UIImageView *copyIdImageView;
@property (nonatomic, strong) XPBeautIDView *beautIDView;
@property(nonatomic, strong) UIView *idEmptyView;
@property (nonatomic, strong) UIButton *copyIdButton;
///魅力等级 等级 铭牌
@property (nonatomic,strong) UIStackView *tagStackView;
///魅力等级
@property (nonatomic,strong) NetImageView *charmImageView;
///等级
@property (nonatomic,strong) NetImageView *experImageView;
///代充
@property (nonatomic,strong) NetImageView *rechargeImageView;
///铭牌图片
@property (nonatomic,strong) NetImageView *vipPlateImageView;
@property (nonatomic,strong) NetImageView *agentPlateImageView;
///新用户
@property (nonatomic,strong) UIImageView *newUserImageView;
///官方的
@property (nonatomic,strong) UIImageView *officialImageView;
///签名
@property (nonatomic,strong) UILabel *signatureLabel;
///VIP等级icon
@property (nonatomic,strong) NetImageView *nobleImageView;
@property (nonatomic, strong) UIStackView *locateDateStackView;
@property (nonatomic, strong) UILabel *locateLabel;
@property (nonatomic, strong) UILabel *fansNum;
@property (nonatomic, strong) UILabel *followersNum;
@property (nonatomic, strong) CPCard *cpCard_1;
@property (nonatomic, strong) CPCard *cpCard_2;
@property (nonatomic, strong) CPCard *cpCard_3;
@property (nonatomic, strong) CPCard *cpCard_4;
@property (nonatomic, strong) UIButton *cpListButton;
@property (nonatomic, strong) UICollectionView *nameplateCollectionView;
@property(nonatomic, strong) XPRoomGiftAnimationParser *personalBGMP4Parser;
@property(nonatomic, strong) NetImageView *personalBGImageView;
@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;
@end
@implementation XPMineUserInfoHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setupUI];
}
return self;
}
+ (CGFloat)namePlateHeight:(NSArray *)list {
CGFloat namePlateHeight = 0;
if (list.count > 0) {
// 固定的 cell 宽度和高度
CGFloat cellWidth = 70;
CGFloat cellHeight = 20;
// collectionView 左右边距
CGFloat sidePadding = kGetScaleWidth(15); // 左右各 15
CGFloat itemSpacing = 4; // cell 间的水平间距
CGFloat lineSpacing = 2; // 行间距
CGFloat collectionViewWidth = KScreenWidth - sidePadding;
// 可用宽度 = collectionView 的总宽度 - 左右边距
CGFloat availableWidth = collectionViewWidth - sidePadding;
// 计算每行能放的 cell 数量
NSInteger itemsPerRow = floor((availableWidth) / (cellWidth + itemSpacing));
// 计算总行数
NSInteger rows = (list.count + itemsPerRow - 1) / itemsPerRow;
// 总高度 = 所有 cell 的高度 + 所有行间距
namePlateHeight = rows * cellHeight + rows * lineSpacing;
}
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;
CGFloat lineHeight = 0;
if (model.userDesc.length > 0) {
// 限定宽度
CGFloat maxWidth = KScreenWidth - 30;
UIFont *font = kFontRegular(13);
// 设置计算属性
NSDictionary *attributes = @{NSFontAttributeName:font};
// 计算文本的矩形区域
CGRect textRect = [model.userDesc boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:attributes
context:nil];
// 计算每行的高度
lineHeight = font.lineHeight;
// 计算行数
numberOfLines = ceil(textRect.size.height / lineHeight);
}
// 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;
}
if (cps > 0) {
height = height + kGetScaleWidth(135) * cps + 10 * cps;
}
return height;
}
#pragma mark - Private Method
- (void)setupUI {
self.backgroundColor = [UIColor clearColor];
[self setupAlbumScrollView];
[self addSubview:self.pageButton];
[self.pageButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self).offset(kGetScaleWidth(-15));
make.top.mas_equalTo(self).offset(kNavigationHeight + 80);
make.size.mas_equalTo(CGSizeMake(30, 18));
}];
[self addSubview:self.userInfoView];
[self.userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self);
make.top.mas_equalTo(kGetScaleWidth(195));
make.bottom.mas_equalTo(self);
}];
[self.userInfoView addSubview:self.personalBGMP4];
[self.userInfoView addSubview:self.personalBGSvga];
[self.userInfoView addSubview:self.personalBGImageView];
[self setupAvatars];
[self.personalBGImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.avatarView).offset(-15);
make.leading.trailing.mas_equalTo(self.userInfoView);
make.height.mas_equalTo(kGetScaleWidth(370));
}];
[self setupNameArea];
[self setupNameplateArea];
[self setupMedalsArea];
[self setupLocateArea];
[self setupCustomDesc];
[self setupRelationshipArea];
[self setupCPArea];
}
- (void)setupAlbumScrollView {
[self addSubview:self.pi_cycleScrollView];
[self.pi_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.mas_equalTo(self);
make.height.mas_equalTo(kGetScaleWidth(195));
}];
// 创建一个新的视图作为蒙层
UIView *overlay = [[UIView alloc] initWithFrame:self.pi_cycleScrollView.bounds];
overlay.userInteractionEnabled = NO;
// 设置蒙层背景色为黑色,透明度为 0.5
overlay.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
// 将蒙层添加到目标视图
[self.pi_cycleScrollView addSubview:overlay];
// 确保蒙层大小适应目标视图的变化
overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[overlay mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.pi_cycleScrollView);
}];
}
- (void)setupAvatars {
[self addSubview:self.avatarView];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(82));
make.leading.mas_equalTo(30);
make.centerY.equalTo(self.userInfoView.mas_top);
}];
[self addSubview:self.headWearImageView];
[self.headWearImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.avatarView);
make.width.height.mas_equalTo(kGetScaleWidth(114));
}];
[self addSubview:self.headWearSvgaImageView];
[self.headWearSvgaImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.avatarView);
make.width.height.mas_equalTo(kGetScaleWidth(114));
}];
[self addSubview:self.reviewIcon];
[self.reviewIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.avatarView);
}];
[self addSubview:self.avatarView_cp];
[self.avatarView_cp mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(82));
make.leading.mas_equalTo(self.headWearSvgaImageView.mas_trailing).offset(kGetScaleWidth(16));
make.centerY.equalTo(self.userInfoView.mas_top);
}];
[self addSubview:self.headWearSvgaImageView_cp_me];
[self.headWearSvgaImageView_cp_me mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.avatarView);
make.width.height.mas_equalTo(kGetScaleWidth(114));
}];
[self addSubview:self.headWearSvgaImageView_cp];
[self.headWearSvgaImageView_cp mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.avatarView_cp);
make.width.height.mas_equalTo(kGetScaleWidth(114));
}];
[self addSubview:self.cpAvatarHeart];
[self.cpAvatarHeart mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.userInfoView.mas_top);
make.centerX.equalTo(self.headWearSvgaImageView.mas_trailing);
make.width.height.mas_equalTo(kGetScaleWidth(38));
}];
[self addSubview:self.cpAvatarFlag];
[self.cpAvatarFlag mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.headWearSvgaImageView);
make.centerX.equalTo(self.headWearSvgaImageView.mas_trailing);
make.width.mas_equalTo(kGetScaleWidth(122));
make.height.mas_equalTo(kGetScaleWidth(35));
}];
}
- (void)setupNameArea {
[self addSubview:self.onlineButton];
[self.onlineButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.userInfoView).offset(-15);
make.top.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(57));
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(72);
}];
[self.onlineButton addSubview:self.onlineIconView];
[self.onlineIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(8);
make.centerY.mas_equalTo(0);
make.width.height.mas_equalTo(16);
}];
@kWeakify(self);
SVGAParser * parser = [[SVGAParser alloc]init];
[parser parseWithNamed:@"pi_new_mine_info_online" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.onlineIconView.loops = 0;
self.onlineIconView.clearsAfterStop = NO;
self.onlineIconView.videoItem = videoItem;
[self.onlineIconView startAnimation];
} failureBlock:^(NSError * _Nonnull error) { }];
[self.userInfoView addSubview:self.nickStackView];
[self.nickStackView addArrangedSubview:self.nameLabel];
[self.nickStackView addArrangedSubview:self.sexImageView];
[self.nickStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
make.top.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(57));
make.height.mas_equalTo(22);
}];
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(35, 16));
}];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// NSLog(@"%@", [NSValue valueWithCGPoint:scrollView.contentOffset]);
}
- (void)setupIDArea {
if (_stack) {
return;
}
UIScrollView *scrollView = [[UIScrollView alloc] init];
_stack = [[UIStackView alloc] init];
self.stack.axis = UILayoutConstraintAxisHorizontal;
self.stack.distribution = UIStackViewDistributionFill;
self.stack.alignment = UIStackViewAlignmentLeading;
self.stack.spacing = 4;
// if (self.userInfo.guildNameplateIcon.length > 0) {
// scrollView.translatesAutoresizingMaskIntoConstraints = NO;
// [self.userInfoView addSubview:scrollView];
// [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.leading.mas_equalTo(kGetScaleWidth(15));
// make.trailing.mas_equalTo(kGetScaleWidth(-15));
// make.top.mas_equalTo(self.nickStackView.mas_bottom).offset(5);
// make.height.mas_equalTo(24);
// }];
// [scrollView addSubview:self.stack];
// [self.stack mas_makeConstraints:^(MASConstraintMaker *make) {
// make.edges.equalTo(scrollView); // 内容视图的边缘与滚动视图一致
// make.height.equalTo(scrollView); // 高度与滚动视图一致,确保仅水平滚动
// }];
//
//// if (isMSRTL()) {
//// _idEmptyView = [[UIView alloc] init];
//// }
// } else {
[self.userInfoView addSubview:self.stack];
[self.stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(15));
make.top.mas_equalTo(self.nickStackView.mas_bottom).offset(5);
make.height.mas_equalTo(24);
}];
// }
[self.stack addArrangedSubview:self.beautIDView];
[self.stack addArrangedSubview:self.idLabel];
[self.stack addArrangedSubview:self.copyIdImageView];
[self.stack addArrangedSubview:self.experImageView];
[self.stack addArrangedSubview:self.charmImageView];
[self.stack addArrangedSubview:self.vipPlateImageView];
[self.stack addArrangedSubview:self.agentPlateImageView];
if (_idEmptyView) {
[self.stack addArrangedSubview:self.idEmptyView];
[self.idEmptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(24);
make.width.mas_equalTo(30);
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[scrollView setContentOffset:CGPointMake(34, 0)];
});
}
[self.beautIDView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(24);
make.width.mas_greaterThanOrEqualTo(10);
}];
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(24);
}];
[self.copyIdImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(20, 20));
}];
[self.experImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(36, 18));
}];
[self.charmImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(36, 18));
}];
[self.vipPlateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(24);
make.width.mas_equalTo(60);
}];
[self.agentPlateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(24);
make.width.mas_equalTo(60);
}];
}
- (void)setupNameplateArea {
[self.userInfoView addSubview:self.nameplateCollectionView];
[self.nameplateCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.nickStackView.mas_bottom).offset(30);
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
make.trailing.mas_equalTo(self.userInfoView);//.offset(kGetScaleWidth(-15));
make.height.mas_equalTo(0);
}];
}
- (void)setupMedalsArea {
// 添加 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(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.medalsScrollView.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.medalsScrollView.mas_bottom).offset(6);
}];
}
- (void)setupCustomDesc {
[self.userInfoView addSubview:self.signatureLabel];
[self.signatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
make.trailing.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(-15));
make.top.mas_equalTo(self.locateLabel.mas_bottom).offset(6);
}];
}
- (void)setupRelationshipArea {
UIStackView *stack = [[UIStackView alloc] init];
stack.axis = UILayoutConstraintAxisHorizontal;
stack.distribution = UIStackViewDistributionFill;
stack.alignment = UIStackViewAlignmentCenter;
stack.spacing = 30;
UIStackView *stack_follow = [[UIStackView alloc] init];
stack_follow.axis = UILayoutConstraintAxisHorizontal;
stack_follow.distribution = UIStackViewDistributionFill;
stack_follow.alignment = UIStackViewAlignmentFirstBaseline;
stack_follow.spacing = 6;
[stack_follow addArrangedSubview:self.followersNum];
UILabel *followerTitle = [UILabel labelInitWithText:YMLocalizedString(@"XPMineHeadView4")
font:kFontRegular(12)
textColor:[UIColor colorWithWhite:1 alpha:0.6]];
[stack_follow addArrangedSubview:followerTitle];
UIStackView *stack_fans = [[UIStackView alloc] init];
stack_fans.axis = UILayoutConstraintAxisHorizontal;
stack_fans.distribution = UIStackViewDistributionFill;
stack_fans.alignment = UIStackViewAlignmentFirstBaseline;
stack_fans.spacing = 6;
[stack_fans addArrangedSubview:self.fansNum];
UILabel *fansTitle = [UILabel labelInitWithText:YMLocalizedString(@"XPMineHeadView5")
font:kFontRegular(12)
textColor:[UIColor colorWithWhite:1 alpha:0.6]];
[stack_fans addArrangedSubview:fansTitle];
[stack addArrangedSubview:stack_follow];
[stack addArrangedSubview:stack_fans];
[self.userInfoView addSubview:stack];
[stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.signatureLabel.mas_bottom).offset(6);
make.leading.mas_equalTo(self.userInfoView).offset(kGetScaleWidth(15));
make.height.mas_equalTo(30);
}];
}
- (void)setupCPArea {
UIView *greenLine = [[UIView alloc] init];
greenLine.layer.backgroundColor = UIColorFromRGB(0x04D5C6).CGColor;
greenLine.layer.cornerRadius = 2;
[self.userInfoView addSubview:greenLine];
[greenLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(15));
make.top.mas_equalTo(self.signatureLabel.mas_bottom).offset(57);
make.size.mas_equalTo(CGSizeMake(3, 15));
}];
UILabel *titleLabel = [UILabel labelInitWithText:@"CP" font:kFontSemibold(16) textColor:[UIColor whiteColor]];
[self.userInfoView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(greenLine.mas_trailing).offset(7);
make.centerY.mas_equalTo(greenLine);
}];
UIButton *cpListButton = [UIButton buttonWithType:UIButtonTypeCustom];
cpListButton.hidden = YES;
[cpListButton setImage:kImage(@"cp_menu") forState:UIControlStateNormal];
[cpListButton addTarget:self action:@selector(clickCPListButton) forControlEvents:UIControlEventTouchUpInside];
[self.userInfoView addSubview:cpListButton];
[cpListButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleLabel);
make.trailing.mas_equalTo(kGetScaleWidth(-15));
make.width.height.mas_equalTo(22);
}];
self.cpListButton = cpListButton;
[self.userInfoView addSubview:self.cpCard_1];
[self.cpCard_1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(titleLabel.mas_bottom).offset(3);
make.width.mas_equalTo(self.userInfoView);
make.height.mas_equalTo(kGetScaleWidth(135));
}];
[self.userInfoView addSubview:self.cpCard_2];
[self.cpCard_2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.cpCard_1.mas_bottom).offset(12);
make.width.mas_equalTo(self.userInfoView);
make.height.mas_equalTo(kGetScaleWidth(135));
}];
[self.userInfoView addSubview:self.cpCard_3];
[self.cpCard_3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.cpCard_2.mas_bottom).offset(12);
make.width.mas_equalTo(self.userInfoView);
make.height.mas_equalTo(kGetScaleWidth(135));
}];
[self.userInfoView addSubview:self.cpCard_4];
[self.cpCard_4 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.cpCard_3.mas_bottom).offset(12);
make.width.mas_equalTo(self.userInfoView);
make.height.mas_equalTo(kGetScaleWidth(135));
}];
}
#pragma mark - UICollectionView Delegate & DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.nameplateList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NameplateCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NameplateCell" forIndexPath:indexPath];
[cell updateCell:[self.nameplateList xpSafeObjectAtIndex:indexPath.row]];
return cell;
}
#pragma mark - SDPhotoBrowserDelegate
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
if(browser.isAvatar == YES){
return [NSURL URLWithString:self.avatarView.imageUrl];
}
NSString *photoUrl = [self.imageUrls xpSafeObjectAtIndex:index];
return [NSURL URLWithString:photoUrl ? photoUrl : @""];
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
return [UIImageConstant defaultBannerPlaceholder];
}
#pragma mark - SDCycleScrollViewDelegate
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
[self.pageButton setTitle:[NSString stringWithFormat:@"%ld/%lu",(index + 1), (unsigned long)self.imageUrls.count] forState:UIControlStateNormal];
UserPhoto * photo = [self.userPhotoArray xpSafeObjectAtIndex:index];
self.reviewIcon.hidden = !photo.isReview;
}
// 轮播图点击
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
NSInteger count = self.imageUrls.count;
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = self.pi_cycleScrollView;
browser.delegate = self;
browser.imageCount = count;
browser.currentImageIndex = index;
browser.isMe = NO;
[browser show];
}
///复制id
-(void)copyNameAction{
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"XPMineUserInfoHeaderView0")];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard. string = [NSString stringWithFormat:@"%ld", (long)_userInfo.erbanNo];
}
#pragma mark - Event Response
-(void)clickAvatarAction{
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc]init];
browser.sourceImagesContainerView = self.avatarView;
browser.delegate = self;
browser.imageCount = 1;
browser.currentImageIndex = 0;
browser.isMe = NO;
browser.isAvatar = YES;
[browser show];
}
- (void)clickCPListButton {
CPListViewController *cpListVC = [[CPListViewController alloc] init];
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:cpListVC animated:YES];
}
- (void)onlineButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineUserInfoHeaderView:didClickGoToRoom:)]) {
[self.delegate xPMineUserInfoHeaderView:self didClickGoToRoom:self.roomUid];
}
}
#pragma mark - Getters And Setters
- (CGFloat)widthOfText:(NSString *)text withFont:(UIFont *)font {
NSDictionary *attributes = @{NSFontAttributeName: font};
CGSize textSize = [text sizeWithAttributes:attributes];
return textSize.width;
}
- (void)setUserInfo:(UserInfoModel *)userInfo {
_userInfo = userInfo;
if (!_userInfo) {
return;
}
if (_personalBGMP4) {
[self.personalBGMP4 stopHWDMP4];
}
if (_personalBGSvga) {
[self.personalBGSvga stopAnimation];
}
if (userInfo.usingPersonalBackground) {
if (![NSString isEmpty:userInfo.usingPersonalBackground.effect]) {
switch (userInfo.usingPersonalBackground.effectType) {
case 0: {
self.personalBGImageView.imageUrl = userInfo.usingPersonalBackground.effect;
}
break;
case 1: {
@kWeakify(self);
[self.personalBGMP4Parser parseWithURL:[userInfo.usingPersonalBackground.effect pureURLString]
completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(self);
if (videoUrl.length) {
[self.personalBGMP4 setMute:YES];
[self.personalBGMP4 playHWDMP4:videoUrl repeatCount:-1 delegate:self];
}
} failureBlock:^(NSError * _Nullable error) {
// NSLog(@"%@", error);
}];
}
break;
case 2: {
SVGAParser *parser = [[SVGAParser alloc] init];
@kWeakify(self);
[parser parseWithURL:[NSURL URLWithString:userInfo.usingPersonalBackground.effect] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.personalBGSvga.videoItem = videoItem;
self.personalBGSvga.loops = 0;
[self.personalBGSvga startAnimation];
} failureBlock:nil];
}
break;
default:
break;
}
} else if(![NSString isEmpty:userInfo.usingPersonalBackground.pic]) {
self.personalBGImageView.imageUrl = userInfo.usingPersonalBackground.pic;
}
}
[self updateNameAndGenderInfo];
[self updateIDInfo];
[self updateLocateAndRegionInfo];
[self updateSignatureInfo];
[self updateRelationShipInfo];
[self updateHeadwearInfo];
self.cpListButton.hidden = (userInfo.uid != [AccountInfoStorage instance].getUid.integerValue);
self.officialImageView.hidden = userInfo.defUser != UserLevelType_Offical;
self.newUserImageView.hidden = !userInfo.newUser;
if (userInfo.userLevelVo.experUrl) {
[self.experImageView loadImageWithUrl:userInfo.userLevelVo.experUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
self.experImageView.image = image;
CGFloat width = image.size.width*20/ (image.size.height > 0 ? image.size.height : 1);
[self.experImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(20);
make.width.mas_equalTo(width);
}];
}];
}
self.experImageView.hidden = userInfo.userLevelVo.experUrl.length <= 0;
if (userInfo.userLevelVo.charmUrl) {
[self.charmImageView loadImageWithUrl:userInfo.userLevelVo.charmUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
self.charmImageView.image = image;
CGFloat width = image.size.width*20/ (image.size.height > 0 ? image.size.height : 1);
[self.charmImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(20);
make.width.mas_equalTo(width);
}];
}] ;
}
self.charmImageView.hidden = userInfo.userLevelVo.charmUrl.length <= 0;
if (userInfo.userVipInfoVO.nameplateUrl.length > 0) {
[self loadNamePlate:userInfo.userVipInfoVO.nameplateUrl targetView:self.vipPlateImageView];
self.vipPlateImageView.hidden = NO;
} else {
self.vipPlateImageView.hidden = YES;
}
if (userInfo.guildNameplateIcon.length > 0) {
[self loadNamePlate:userInfo.guildNameplateIcon targetView:self.agentPlateImageView];
self.agentPlateImageView.hidden = NO;
} else {
self.agentPlateImageView.hidden = YES;
}
self.rechargeImageView.hidden = !_userInfo.isRechargeUser;
[self.userPhotoArray removeAllObjects];
// 轮播图
NSMutableArray * imageUrls = [NSMutableArray array];
if (userInfo.avatar) {
[imageUrls addObject:userInfo.avatar];
if (![self.userPhotoArray containsObject:self.avatarPhoto]) {
[self.userPhotoArray addObject:self.avatarPhoto];
}
self.avatarPhoto.isReview = userInfo.isReview;
self.avatarPhoto.photoUrl = userInfo.avatar;
self.avatarView.imageUrl = userInfo.avatar;
}
if (self.userInfo.privatePhoto.count > 0) {
for (int i = 0; i < self.userInfo.privatePhoto.count; i++) {
UserPhoto * photo = [self.userInfo.privatePhoto xpSafeObjectAtIndex:i];
if (photo.photoUrl.length > 0) {
[self.userPhotoArray addObject:photo];
[imageUrls addObject:photo.photoUrl];
}
}
}
if (imageUrls.count > 0) {
self.imageUrls = imageUrls;
self.pi_cycleScrollView.imageURLStringsGroup = imageUrls;
[self.pageButton setTitle:[NSString stringWithFormat:@"1/%lu",(unsigned long)imageUrls.count] forState:UIControlStateNormal];;
// 要初始化一下当前的审核状态
if(self.userPhotoArray.count > 0){
UserPhoto * photo = [self.userPhotoArray xpSafeObjectAtIndex:0];
if (photo) {
self.reviewIcon.hidden = !photo.isReview;
}
}
}
if (userInfo.userVipInfoVO.vipIcon.length > 0) {
self.nobleImageView.hidden = NO;
self.nobleImageView.imageUrl = userInfo.userVipInfoVO.vipIcon;
} else {
self.nobleImageView.hidden = YES;
}
// 更新勋章显示
[self updateMedalsDisplay:userInfo.medalsPic];
}
- (void)loadNamePlate:(NSString *)imagePath targetView:(NetImageView *)targetView {
[targetView loadImageWithUrl:imagePath completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
if (image) {
CGSize size = image.size;
[targetView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(round(size.width * 24/size.height));
}];
targetView.image = image;
}
}];
}
- (void)setRoomUid:(NSString *)roomUid {
_roomUid = roomUid;
if([XPSkillCardPlayerManager shareInstance].isInRoom == YES || [[XPRoomMiniManager shareManager] getRoomInfo] != nil){
self.onlineButton.hidden = _roomUid.length <= 0;
}else{
self.onlineButton.hidden = YES;
}
}
- (void)setCpUsers:(NSArray<RelationUserVO *> *)cpUsers {
_cpUsers = cpUsers;
RelationUserVO *vo_1 = [cpUsers xpSafeObjectAtIndex:0];
self.cpCard_1.usersAvatar = self.userInfo.avatar;
if (vo_1) {
[self.cpCard_1 updateForUserPage:vo_1];
}
RelationUserVO *vo_2 = [cpUsers xpSafeObjectAtIndex:1];
self.cpCard_2.usersAvatar = self.userInfo.avatar;
[self.cpCard_2 setHidden:!vo_2];
if (vo_2) {
[self.cpCard_2 updateForUserPage:vo_2];
}
RelationUserVO *vo_3 = [cpUsers xpSafeObjectAtIndex:2];
self.cpCard_3.usersAvatar = self.userInfo.avatar;
[self.cpCard_3 setHidden:!vo_3];
if (vo_3) {
[self.cpCard_3 updateForUserPage:vo_3];
}
RelationUserVO *vo_4 = [cpUsers xpSafeObjectAtIndex:3];
self.cpCard_4.usersAvatar = self.userInfo.avatar;
[self.cpCard_4 setHidden:!vo_4];
if (vo_4) {
[self.cpCard_4 updateForUserPage:vo_4];
}
}
- (void)setRelationUser:(RelationUserVO *)relationUser {
_relationUser = relationUser;
BOOL hideCPAvatarContent = NO;
if (relationUser.showCpAvatar) {
hideCPAvatarContent = [relationUser isEmptyRelation];
} else {
hideCPAvatarContent = YES;
}
if (hideCPAvatarContent) {
[self.headWearSvgaImageView_cp stopAnimation];
} else {
[self playCPSVGA:relationUser.cpLevel];
}
self.avatarView_cp.hidden = hideCPAvatarContent;
self.cpAvatarHeart.hidden = hideCPAvatarContent;
self.cpAvatarFlag.hidden = hideCPAvatarContent;
self.headWearSvgaImageView_cp.hidden = hideCPAvatarContent;
self.avatarView_cp.imageUrl = relationUser.cpAvatar;
NSString *imagePath = [NSString stringWithFormat:@"cp_avatar_flag_lv_%ld", relationUser.cpLevel];
self.cpAvatarFlag.image = kImage(imagePath);
}
- (void)setNameplateList:(NSArray<NameplateModel *> *)nameplateList {
_nameplateList = nameplateList;
[self.nameplateCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([XPMineUserInfoHeaderView namePlateHeight:nameplateList]);
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.nameplateCollectionView reloadData];
});
}
- (void)updateNameAndGenderInfo {
self.nameLabel.text = self.userInfo.nick;
UIImage *sexBackgroundImage = nil;
if (self.userInfo.gender == GenderType_Male) {
sexBackgroundImage = [UIImage gradientColorImageFromColors:@[UIColorRGBAlpha(0x6BB3FF, 0.5),UIColorFromRGB(0x6BB3FF)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(35, 16)];
} else {
sexBackgroundImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xF2A0C3),UIColorFromRGB(0xEB74A6)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(35, 16)];
}
[self.sexImageView setTitle:[NSString getAgeWithBirth:self.userInfo.birth] forState:UIControlStateNormal];
[self.sexImageView setBackgroundImage:sexBackgroundImage forState:UIControlStateNormal];
}
- (void)updateIDInfo {
NSString *text = [NSString stringWithFormat:@"%ld", (long)self.userInfo.erbanNo];
[self setupIDArea];
if (self.userInfo.hasPrettyErbanNo) {
self.idLabel.hidden = YES;
self.beautIDView.hidden = NO;
self.beautIDView.num = text;
} else {
self.idLabel.hidden = NO;
self.beautIDView.hidden = YES;
self.idLabel.text = [NSString stringWithFormat:@"ID:%@", text];
}
}
- (void)updateLocateAndRegionInfo {
NSString *locateString = @"";
if (self.userInfo.region.length > 0) {
locateString = [NSString stringWithFormat:@"%@ | ", self.userInfo.region];
}
NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.userInfo.birth/1000];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateString = [dateFormatter stringFromDate:date];
self.locateLabel.text = [NSString stringWithFormat:@"%@%@", locateString, dateString];
}
- (void)updateSignatureInfo {
self.signatureLabel.text = _userInfo.userDesc.length > 0 ? self.userInfo.userDesc : YMLocalizedString(@"XPMineUserInfoHeaderView6");
}
- (void)updateRelationShipInfo {
self.fansNum.text = [@(self.userInfo.fansNum) stringValue];
self.followersNum.text = [@(self.userInfo.followNum) stringValue];
}
- (void)updateHeadwearInfo {
NSString *headerUrl = self.userInfo.headwearEffect.length > 0 ? self.userInfo.headwearEffect : self.userInfo.headwearPic;
if (headerUrl.length == 0) {
self.headWearImageView.hidden = YES;
self.headWearSvgaImageView.hidden = YES;
} else {
if ([self.userInfo isHeadWearSVGA]) {
[self playSVGA:headerUrl];
} else {
[self playAnimate:headerUrl];
}
}
}
- (void)playSVGA:(NSString *)svgaUrlString {
[self.headWearSvgaImageView setImageName:svgaUrlString];
}
- (void)playCPSVGA:(NSInteger)level {
if (level == 0) {
return;
}
self.headWearSvgaImageView.videoItem = nil;
[self.headWearSvgaImageView stopAnimation];
@kWeakify(self);
SVGAParser *parser = [SVGAParser new];
[parser parseWithNamed:@(level).stringValue
inBundle:[NSBundle mainBundle]
completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.headWearSvgaImageView_cp_me.hidden = NO;
self.headWearSvgaImageView_cp.hidden = NO;
self.headWearSvgaImageView_cp_me.videoItem = videoItem;
[self.headWearSvgaImageView_cp_me startAnimation];
self.headWearSvgaImageView_cp.videoItem = videoItem;
[self.headWearSvgaImageView_cp startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
}
- (void)playAnimate:(NSString *)headwearUrlString {
self.headWearImageView.hidden = NO;
NSURL *url = [NSURL URLWithString:headwearUrlString];
@kWeakify(self);
[self.manager loadSpriteSheetImageWithURL:url completionBlock:^(YYSpriteSheetImage * _Nullable sprit) {
@kStrongify(self);
self.headWearImageView.image = sprit;
} failureBlock:^(NSError * _Nullable error) {}];
}
#pragma mark - MP4 delegate
- (BOOL)shouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config {
return YES;
}
- (void)viewDidFailPlayMP4:(NSError *)error {
[self.personalBGMP4 removeFromSuperview];
}
- (void)viewDidFinishPlayMP4:(NSInteger)totalFrameCount view:(VAPView *)container {
}
#pragma mark - Getters
- (UIView *)userInfoView {
if (!_userInfoView) {
_userInfoView = [[UIView alloc] init];
_userInfoView.backgroundColor = UIColorFromRGB(0x08151A);
}
return _userInfoView;
}
- (UIStackView *)nickStackView {
if (!_nickStackView) {
_nickStackView = [[UIStackView alloc] init];
_nickStackView.backgroundColor = [UIColor clearColor];
_nickStackView.axis = UILayoutConstraintAxisHorizontal;
_nickStackView.distribution = UIStackViewDistributionFillProportionally;
_nickStackView.alignment = UIStackViewAlignmentCenter;
_nickStackView.spacing = 4;
if (isMSRTL()) {
_nickStackView.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
}
}
return _nickStackView;
}
- (UILabel *)nameLabel {
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.font = kFontMedium(16);
_nameLabel.textColor = [UIColor whiteColor];
_nameLabel.numberOfLines = 1;
[_nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_nameLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _nameLabel;
}
- (UIButton *)sexImageView {
if (!_sexImageView) {
_sexImageView = [[UIButton alloc] init];
[_sexImageView setImage:kImage(@"home_age_boy_icon") forState:UIControlStateNormal];
[_sexImageView setImage:kImage(@"home_age_girl_icon") forState:UIControlStateSelected];
_sexImageView.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightMedium];
[_sexImageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_sexImageView.imageEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 0);
_sexImageView.layer.cornerRadius = 14/2;
_sexImageView.layer.masksToBounds = YES;
}
return _sexImageView;
}
- (UILabel *)idLabel {
if (!_idLabel) {
_idLabel = [[UILabel alloc] init];
_idLabel.font = kFontMedium(12);
_idLabel.textColor = [UIColor whiteColor];
_idLabel.textAlignment = NSTextAlignmentCenter;
_idLabel.userInteractionEnabled = YES;
_idLabel.clipsToBounds = NO;
_idLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyNameAction)];
[_idLabel addGestureRecognizer:tap];
}
return _idLabel;
}
- (UIImageView *)copyIdImageView {
if (!_copyIdImageView) {
_copyIdImageView = [[UIImageView alloc] init];
_copyIdImageView.userInteractionEnabled = YES;
_copyIdImageView.contentMode = UIViewContentModeScaleAspectFit;
_copyIdImageView.image = [UIImage getLanguageImage:@"user_card_copy_id1"];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyNameAction)];
[_copyIdImageView addGestureRecognizer:tap];
}
return _copyIdImageView;
}
- (UIButton *)copyIdButton {
if (!_copyIdButton) {
_copyIdButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_copyIdButton addTarget:self action:@selector(copyNameAction) forControlEvents:UIControlEventTouchUpInside];
}
return _copyIdButton;
}
- (XPBeautIDView *)beautIDView {
if (!_beautIDView) {
_beautIDView = [[XPBeautIDView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyNameAction)];
[_beautIDView addGestureRecognizer:tap];
}
return _beautIDView;
}
- (SVGAImageView *)onlineIconView {
if (_onlineIconView == nil) {
_onlineIconView = [[SVGAImageView alloc]init];
_onlineIconView.contentMode = UIViewContentModeScaleToFill;
_onlineIconView.userInteractionEnabled = NO;
_onlineIconView.backgroundColor = [UIColor clearColor];
}
return _onlineIconView;
}
- (UIButton *)onlineButton {
if (!_onlineButton) {
_onlineButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_onlineButton setBackgroundColor:UIColorFromRGB(0x04D5C6)];
[_onlineButton addTarget:self
action:@selector(onlineButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[_onlineButton setTitle:[NSString stringWithFormat:@"%@ ", YMLocalizedString(@"XPMineSimpleUserInfoHeaderView2")]
forState:UIControlStateNormal];
[_onlineButton.titleLabel setFont:kFontMedium(12)];
[_onlineButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
_onlineButton.layer.cornerRadius = 11;
_onlineButton.layer.masksToBounds = YES;
_onlineButton.hidden = YES;
_onlineButton.imageEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);
_onlineButton.titleEdgeInsets = UIEdgeInsetsMake(0, 34, 0, 0);
}
return _onlineButton;
}
- (SDCycleScrollView *)pi_cycleScrollView {
if (!_pi_cycleScrollView) {
_pi_cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero
delegate:self
placeholderImage:[UIImageConstant defaultBannerPlaceholder]];
_pi_cycleScrollView.backgroundColor = [UIColor clearColor];
_pi_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
_pi_cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
_pi_cycleScrollView.autoScroll = NO;
// SDCycleScrollView没有适配阿语在RTL下会乱滚都用LTR算了
_pi_cycleScrollView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
for (UIView *subView in _pi_cycleScrollView.subviews) {
subView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
}
return _pi_cycleScrollView;
}
- (UIButton *)pageButton {
if (!_pageButton) {
_pageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_pageButton setTitleColor:UIColorFromRGB(0xfffcfc) forState:UIControlStateNormal];
_pageButton.titleLabel.font = kFontMedium(11);
_pageButton.backgroundColor = UIColorRGBAlpha(0x000000, 0.6);
_pageButton.layer.cornerRadius = 9;
_pageButton.layer.masksToBounds = YES;
}
return _pageButton;
}
- (UIImageView *)reviewIcon {
if (!_reviewIcon) {
_reviewIcon = [[UIImageView alloc] init];
_reviewIcon.image = [UIImage getLanguageImage:@"mine_album_reviewing"];
_reviewIcon.contentMode = UIViewContentModeScaleAspectFit;
_reviewIcon.hidden = YES;
}
return _reviewIcon;
}
- (UIStackView *)tagStackView {
if (!_tagStackView) {
_tagStackView = [[UIStackView alloc] init];
_tagStackView.axis = UILayoutConstraintAxisHorizontal;
_tagStackView.distribution = UIStackViewDistributionFill;
_tagStackView.alignment = UIStackViewAlignmentCenter;
_tagStackView.spacing = 6;
}
return _tagStackView;
}
- (NetImageView *)experImageView {
if (!_experImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.imageType = ImageTypeUserCardLevel;
_experImageView = [[NetImageView alloc] initWithConfig:config];
_experImageView.userInteractionEnabled = YES;
_experImageView.hidden = YES;
_experImageView.contentMode = UIViewContentModeScaleToFill;
}
return _experImageView;
}
- (NetImageView *)charmImageView {
if (!_charmImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.imageType = ImageTypeUserCardLevel;
_charmImageView = [[NetImageView alloc] initWithConfig:config];
_charmImageView.userInteractionEnabled = YES;
_charmImageView.hidden = YES;
_charmImageView.contentMode = UIViewContentModeScaleToFill;
}
return _charmImageView;
}
- (NetImageView *)vipPlateImageView {
if (!_vipPlateImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.imageType = ImageTypeUserCardLevel;
_vipPlateImageView = [[NetImageView alloc] initWithConfig:config];
_vipPlateImageView.userInteractionEnabled = YES;
_vipPlateImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _vipPlateImageView;
}
- (NetImageView *)agentPlateImageView {
if (!_agentPlateImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.imageType = ImageTypeUserCardLevel;
_agentPlateImageView = [[NetImageView alloc] initWithConfig:config];
_agentPlateImageView.userInteractionEnabled = YES;
_agentPlateImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _agentPlateImageView;
}
- (UIImageView *)newUserImageView {
if (!_newUserImageView) {
_newUserImageView = [[UIImageView alloc] init];
_newUserImageView.userInteractionEnabled = YES;
_newUserImageView.image = [UIImage getLanguageImage:@"common_new_user"];
_newUserImageView.hidden = YES;
}
return _newUserImageView;
}
- (UIImageView *)officialImageView {
if (!_officialImageView) {
_officialImageView = [[UIImageView alloc] init];
_officialImageView.userInteractionEnabled = YES;
_officialImageView.image = [UIImage imageNamed:@"app_admin_icon"];
_officialImageView.hidden = YES;
}
return _officialImageView;
}
- (UILabel *)signatureLabel {
if (!_signatureLabel) {
_signatureLabel = [[UILabel alloc] init];
_signatureLabel.font = kFontRegular(13);
_signatureLabel.textColor = [UIColor colorWithWhite:1 alpha:0.6];
_signatureLabel.numberOfLines = 0;
_signatureLabel.textAlignment = NSTextAlignmentNatural;
}
return _signatureLabel;
}
- (NSMutableArray *)userPhotoArray {
if (!_userPhotoArray) {
_userPhotoArray = [NSMutableArray array];
}
return _userPhotoArray;
}
- (UserPhoto *)avatarPhoto {
if (!_avatarPhoto) {
_avatarPhoto = [[UserPhoto alloc] init];
}
return _avatarPhoto;
}
-(NetImageView *)avatarView{
if (!_avatarView){
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.imageType = ImageTypeUserIcon;
_avatarView = [[NetImageView alloc]initWithConfig:config];
_avatarView.layer.cornerRadius = kGetScaleWidth(41);
_avatarView.layer.masksToBounds = YES;
_avatarView.layer.borderWidth = 1;
_avatarView.userInteractionEnabled = YES;
_avatarView.layer.borderColor = [UIColor whiteColor].CGColor;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickAvatarAction)];
[_avatarView addGestureRecognizer:tap];
}
return _avatarView;
}
-(NetImageView *)avatarView_cp{
if (!_avatarView_cp){
NetImageConfig * config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.imageType = ImageTypeUserIcon;
_avatarView_cp = [[NetImageView alloc]initWithConfig:config];
_avatarView_cp.hidden = YES;
_avatarView_cp.layer.cornerRadius = kGetScaleWidth(41);
_avatarView_cp.layer.masksToBounds = YES;
_avatarView_cp.layer.borderWidth = 1;
_avatarView_cp.userInteractionEnabled = YES;
_avatarView_cp.layer.borderColor = [UIColor whiteColor].CGColor;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickAvatarAction)];
[_avatarView_cp addGestureRecognizer:tap];
}
return _avatarView_cp;
}
- (YYAnimatedImageView *)headWearImageView {
if (!_headWearImageView) {
_headWearImageView = [[YYAnimatedImageView alloc] init];
_headWearImageView.backgroundColor = [UIColor clearColor];
_headWearImageView.contentMode = UIViewContentModeScaleAspectFit;
_headWearImageView.layer.masksToBounds = YES;
_headWearImageView.layer.cornerRadius = 10;
}
return _headWearImageView;
}
- (SpriteSheetImageManager *)manager {
if (!_manager) {
_manager = [[SpriteSheetImageManager alloc] init];
}
return _manager;
}
- (NetImageView *)rechargeImageView{
if(!_rechargeImageView){
_rechargeImageView = [NetImageView new];
_rechargeImageView.image = [UIImage getLanguageImage:@"mine_info_recharge"];
_rechargeImageView.hidden = YES;
}
return _rechargeImageView;
}
- (NetImageView *)nobleImageView {
if (!_nobleImageView) {
_nobleImageView = [[NetImageView alloc] init];
_nobleImageView.contentMode = UIViewContentModeScaleAspectFit;
_nobleImageView.hidden = YES;
}
return _nobleImageView;
}
- (UIStackView *)locateDateStackView {
if (!_locateDateStackView) {
_locateDateStackView = [[UIStackView alloc] init];
_locateDateStackView.backgroundColor = [UIColor clearColor];
_locateDateStackView.axis = UILayoutConstraintAxisHorizontal;
_locateDateStackView.distribution = UIStackViewDistributionEqualCentering;
_locateDateStackView.alignment = UIStackViewAlignmentCenter;
_locateDateStackView.spacing = 6;
}
return _locateDateStackView;
}
- (UILabel *)locateLabel {
if (!_locateLabel) {
_locateLabel = [[UILabel alloc] init];
_locateLabel.font = kFontMedium(12);
_locateLabel.textColor = [UIColor colorWithWhite:1 alpha:0.6];
}
return _locateLabel;
}
- (UILabel *)fansNum {
if (!_fansNum) {
_fansNum = [[UILabel alloc] init];
_fansNum.font = kFontSemibold(20);
_fansNum.textColor = [UIColor whiteColor];
}
return _fansNum;
}
- (UILabel *)followersNum {
if (!_followersNum) {
_followersNum = [[UILabel alloc] init];
_followersNum.font = kFontSemibold(20);
_followersNum.textColor = [UIColor whiteColor];
}
return _followersNum;
}
- (SVGAImageView *)headWearSvgaImageView {
if (!_headWearSvgaImageView) {
_headWearSvgaImageView = [[SVGAImageView alloc]init];
_headWearSvgaImageView.backgroundColor = [UIColor clearColor];
_headWearSvgaImageView.frame = self.bounds;
_headWearSvgaImageView.userInteractionEnabled = YES;
_headWearSvgaImageView.autoPlay = YES;
}
return _headWearSvgaImageView;
}
- (SVGAImageView *)headWearSvgaImageView_cp_me {
if (!_headWearSvgaImageView_cp_me) {
_headWearSvgaImageView_cp_me = [[SVGAImageView alloc]init];
_headWearSvgaImageView_cp_me.hidden = YES;
_headWearSvgaImageView_cp_me.backgroundColor = [UIColor clearColor];
_headWearSvgaImageView_cp_me.frame = self.bounds;
_headWearSvgaImageView_cp_me.userInteractionEnabled = YES;
_headWearSvgaImageView_cp_me.autoPlay = YES;
}
return _headWearSvgaImageView_cp_me;
}
- (SVGAImageView *)headWearSvgaImageView_cp {
if (!_headWearSvgaImageView_cp) {
_headWearSvgaImageView_cp = [[SVGAImageView alloc]init];
_headWearSvgaImageView_cp.hidden = YES;
_headWearSvgaImageView_cp.backgroundColor = [UIColor clearColor];
_headWearSvgaImageView_cp.frame = self.bounds;
_headWearSvgaImageView_cp.userInteractionEnabled = YES;
_headWearSvgaImageView_cp.autoPlay = YES;
}
return _headWearSvgaImageView_cp;
}
- (CPCard *)cpCard_1 {
if (!_cpCard_1) {
_cpCard_1 = [[CPCard alloc] init];
_cpCard_1.isListItem = NO;
}
return _cpCard_1;
}
- (CPCard *)cpCard_2 {
if (!_cpCard_2) {
_cpCard_2 = [[CPCard alloc] init];
_cpCard_2.isListItem = NO;
_cpCard_2.hidden = YES;
}
return _cpCard_2;
}
- (CPCard *)cpCard_3 {
if (!_cpCard_3) {
_cpCard_3 = [[CPCard alloc] init];
_cpCard_3.isListItem = NO;
_cpCard_3.hidden = YES;
}
return _cpCard_3;
}
- (CPCard *)cpCard_4 {
if (!_cpCard_4) {
_cpCard_4 = [[CPCard alloc] init];
_cpCard_4.isListItem = NO;
_cpCard_4.hidden = YES;
}
return _cpCard_4;
}
- (UIImageView *)cpAvatarHeart {
if (!_cpAvatarHeart) {
_cpAvatarHeart = [[UIImageView alloc] initWithImage:kImage(@"cp_avatar_heart")];
_cpAvatarHeart.hidden = YES;
}
return _cpAvatarHeart;
}
- (UIImageView *)cpAvatarFlag {
if (!_cpAvatarFlag) {
_cpAvatarFlag = [[UIImageView alloc] init];
_cpAvatarFlag.hidden = YES;
}
return _cpAvatarFlag;
}
- (UICollectionView *)nameplateCollectionView {
if (!_nameplateCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(72, 20);
layout.minimumLineSpacing = 2;
layout.minimumInteritemSpacing = 4;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_nameplateCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_nameplateCollectionView.backgroundColor = [UIColor clearColor];
_nameplateCollectionView.scrollEnabled = NO;
_nameplateCollectionView.delegate = self;
_nameplateCollectionView.dataSource = self;
_nameplateCollectionView.scrollEnabled = YES;
[_nameplateCollectionView registerClass:[NameplateCell class] forCellWithReuseIdentifier:@"NameplateCell"];
}
return _nameplateCollectionView;
}
- (VAPView *)personalBGMP4 {
if (!_personalBGMP4) {
_personalBGMP4 = [[VAPView alloc] initWithFrame:CGRectMake(0, kGetScaleWidth(-82/2), KScreenWidth, kGetScaleWidth(370))];
_personalBGMP4.contentMode = UIViewContentModeScaleAspectFill;
_personalBGMP4.hwd_Delegate = self;
}
return _personalBGMP4;
}
- (SVGAImageView *)personalBGSvga {
if (_personalBGSvga == nil) {
_personalBGSvga = [[SVGAImageView alloc] initWithFrame:CGRectMake(0, -20, KScreenWidth, kGetScaleWidth(370))];
_personalBGSvga.contentMode = UIViewContentModeScaleToFill;
_personalBGSvga.userInteractionEnabled = NO;
_personalBGSvga.backgroundColor = [UIColor clearColor];
}
return _personalBGSvga;
}
- (XPRoomGiftAnimationParser *)personalBGMP4Parser {
if (!_personalBGMP4Parser) {
_personalBGMP4Parser = [[XPRoomGiftAnimationParser alloc] init];
}
return _personalBGMP4Parser;
}
- (NetImageView *)personalBGImageView {
if (!_personalBGImageView) {
_personalBGImageView = [[NetImageView alloc] initWithFrame:CGRectMake(0, kGetScaleWidth(-50), KScreenWidth, kGetScaleWidth(370))];
_personalBGImageView.contentMode = UIViewContentModeScaleAspectFill;
}
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];
_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.medalsScrollView.hidden = YES;
return;
}
self.medalsScrollView.hidden = NO;
NSMutableArray<VAPView *> *mp4Views = [NSMutableArray array];
// 最多显示 10 个勋章
NSInteger count = MIN(medals.count, 2);
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(kGetScaleWidth(30))
.priority(UILayoutPriorityRequired);
}];
// 设置内容压缩阻力优先级,防止被压缩
[medalContainer setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[medalContainer setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
// 设置内容拥抱优先级,防止被拉伸
[medalContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[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];
}
- (void)stopAllMedalsMP4 {
for (VAPView *mp4View in self.medalMP4Views) {
[mp4View stopHWDMP4];
}
self.medalMP4Views = @[];
}
- (void)dealloc {
[self stopAllMedalsMP4];
}
@end