Files
yinmeng-ios/xplan-ios/Main/Home/View/XPNewHomeHeaderView.m
chenshuanglin 71a1b6b559 UI调整
2023-03-21 17:59:16 +08:00

379 lines
13 KiB
Objective-C

//
// XPNewHomeHeaderView.m
// xplan-ios
//
// Created by XY on 2023/3/3.
//
#import "XPNewHomeHeaderView.h"
///Third
#import <Masonry.h>
#import <UIButton+WebCache.h>
#import <ReactiveObjC.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
#import "UIImage+Utils.h"
#import "XPCycleVerticalView.h"
#import "NetImageView.h"
///Model
#import "XPHomeGiftRecordModel.h"
#import "HomeMenuInfoModel.h"
@interface XPNewHomeHeaderView()
/// 交友派对
@property (nonatomic, strong) UIButton *partyView;
/// 小游戏
@property (nonatomic, strong) UIButton *gameView;
/// 听电台
@property (nonatomic, strong) UIButton *radioView;
/// 一键匹配
@property (nonatomic, strong) UIButton *matchView;
/// 绿点
@property (nonatomic, strong) UIImageView *greenDot;
/// 在线人数
@property (nonatomic, strong) UILabel *onlineNumLabel;
@property (nonatomic, strong) NetImageView *matchAvatar1;
@property (nonatomic, strong) NetImageView *matchAvatar2;
@property (nonatomic, strong) NetImageView *matchAvatar3;
/// 热门
@property (nonatomic, strong) UIImageView *hotView;
@property (nonatomic, strong) UIImageView *hotTextImageView;
@property (nonatomic, strong) XPCycleVerticalView *messageView;
@end
@implementation XPNewHomeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.partyView];
[self addSubview:self.gameView];
[self addSubview:self.radioView];
[self addSubview:self.matchView];
[self.matchView addSubview:self.greenDot];
[self.matchView addSubview:self.onlineNumLabel];
[self.matchView addSubview:self.matchAvatar1];
[self.matchView addSubview:self.matchAvatar2];
[self.matchView addSubview:self.matchAvatar3];
[self addSubview:self.hotView];
[self.hotView addSubview:self.hotTextImageView];
[self.hotView addSubview:self.messageView];
@weakify(self);
self.messageView.block = ^(NSInteger index) {
@strongify(self);
if (self.messageList.count == 0) {
return;
}
if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewClickScrollMessage:)]) {
XPHomeGiftRecordModel *model = self.messageList[index];
[self.delegate homeHeaderViewClickScrollMessage:model];
}
};
}
- (void)initSubViewConstraints {
CGFloat partyWidth = 94.0*kScreenScale;
CGFloat partyHeight = 120.0/94.0*partyWidth;
[self.partyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(15);
make.top.mas_equalTo(15);
make.width.mas_equalTo(partyWidth);
make.height.mas_equalTo(partyHeight);
}];
CGFloat gameWidth = (KScreenWidth - 15 -partyWidth - 8 - 3 -15)/2.0;
CGFloat gameHeight = 56.0/120.0*gameWidth;
[self.gameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.partyView.mas_right).offset(8);
make.top.mas_equalTo(self.partyView);
make.width.mas_equalTo(gameWidth);
make.height.mas_equalTo(gameHeight);
}];
[self.radioView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.gameView.mas_right).offset(3);
make.top.mas_equalTo(self.partyView);
make.width.mas_equalTo(gameWidth);
make.height.mas_equalTo(gameHeight);
}];
CGFloat matchWidth = KScreenWidth - 15 - partyWidth - 8 - 15;
CGFloat matchHeight = 56.0/243.0*matchWidth;
[self.matchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.gameView);
make.bottom.mas_equalTo(self.partyView);
make.width.mas_equalTo(matchWidth);
make.height.mas_equalTo(matchHeight);
}];
CGFloat onlineNumTop = 32.0/56.0*matchHeight;
[self.onlineNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(onlineNumTop);
make.left.mas_equalTo(self.greenDot.mas_right).offset(4);
}];
[self.greenDot mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.onlineNumLabel);
make.left.mas_equalTo(10);
make.size.mas_equalTo(CGSizeMake(4, 4));
}];
[self.matchAvatar3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-11);
make.centerY.mas_equalTo(8);
make.width.height.mas_equalTo(22);
}];
[self.matchAvatar2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.matchAvatar3.mas_left).offset(-8);
make.centerY.mas_equalTo(0);
make.width.height.mas_equalTo(36);
}];
[self.matchAvatar1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.matchAvatar2.mas_left).offset(-8);
make.centerY.mas_equalTo(self.matchAvatar3);
make.width.height.mas_equalTo(self.matchAvatar3);
}];
CGFloat hotHeight = 72.0*kScreenScale;
[self.hotView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(15);
make.right.mas_equalTo(-15);
make.height.mas_equalTo(hotHeight);
make.top.mas_equalTo(self.partyView.mas_bottom).offset(20);
}];
[self.hotTextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(22*kScreenScale);
make.top.mas_equalTo(8*kScreenScale);
make.width.mas_equalTo(26);
make.height.mas_equalTo(13);
}];
[self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.mas_equalTo(0);
make.height.mas_equalTo(self.hotView.mas_height).multipliedBy(0.64);
make.right.mas_equalTo(0);
}];
}
/// 获取headerView的高度
+ (NSUInteger)getHeaderViewHeight {
CGFloat height = 15;
CGFloat partyWidth = 94.0*kScreenScale;
CGFloat partyHeight = 120.0/94.0*partyWidth;
height += partyHeight;
height += 20;
CGFloat hotHeight = 72.0*kScreenScale;
height += hotHeight;
height += 15;
return (NSUInteger)height;
}
#pragma mark - Event Response
- (void)partyViewAction {
if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewClickMenu:)]) {
if (self.menuList.count >0) {
[self.delegate homeHeaderViewClickMenu:self.menuList[0]];
}
}
}
- (void)gameViewAction {
if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewClickMenu:)]) {
if (self.menuList.count >1) {
[self.delegate homeHeaderViewClickMenu:self.menuList[1]];
}
}
}
- (void)radioViewAction {
if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewClickMenu:)]) {
if (self.menuList.count >2) {
[self.delegate homeHeaderViewClickMenu:self.menuList[2]];
}
}
}
- (void)matchViewAction {
if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewClickMenu:)]) {
if (self.menuList.count >3) {
[self.delegate homeHeaderViewClickMenu:self.menuList[3]];
}
}
}
#pragma mark - Getters And Setters
- (void)setMenuList:(NSArray<HomeMenuInfoModel *> *)menuList {
_menuList = menuList;
NSUInteger count = menuList.count;
if (count > 0) {
NSURL *url = [NSURL URLWithString:_menuList[0].icon];
[self.partyView sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
self.partyView.hidden = NO;
}
if (count > 1) {
NSURL *url = [NSURL URLWithString:_menuList[1].icon];
[self.gameView sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
self.gameView.hidden = NO;
}
if (count > 2) {
NSURL *url = [NSURL URLWithString:_menuList[2].icon];
[self.radioView sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
self.radioView.hidden = NO;
}
if (count > 3) {
NSURL *url = [NSURL URLWithString:[_menuList[3].icon stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[self.matchView sd_setBackgroundImageWithURL:url forState:UIControlStateNormal];
self.onlineNumLabel.text = [NSString stringWithFormat:@"%@人组队中",_menuList[3].resourceContent];
self.matchView.hidden = NO;
}
}
- (void)setMessageList:(NSArray<XPHomeGiftRecordModel *> *)messageList {
_messageList = messageList;
self.messageView.dataArray = _messageList;
}
- (UIButton *)partyView {
if (!_partyView) {
_partyView = [UIButton buttonWithType:UIButtonTypeCustom];
[_partyView setBackgroundImage:[UIImage imageNamed:@"home_head_party"] forState:UIControlStateNormal];
[_partyView addTarget:self action:@selector(partyViewAction) forControlEvents:UIControlEventTouchUpInside];
_partyView.hidden = YES;
}
return _partyView;
}
- (UIButton *)gameView {
if (!_gameView) {
_gameView = [UIButton buttonWithType:UIButtonTypeCustom];
[_gameView setBackgroundImage:[UIImage imageNamed:@"home_head_game"] forState:UIControlStateNormal];
[_gameView addTarget:self action:@selector(gameViewAction) forControlEvents:UIControlEventTouchUpInside];
_gameView.hidden = YES;
}
return _gameView;
}
- (UIButton *)radioView {
if (!_radioView) {
_radioView = [UIButton buttonWithType:UIButtonTypeCustom];
[_radioView setBackgroundImage:[UIImage imageNamed:@"home_head_radio"] forState:UIControlStateNormal];
[_radioView addTarget:self action:@selector(radioViewAction) forControlEvents:UIControlEventTouchUpInside];
_radioView.hidden = YES;
}
return _radioView;
}
- (UIButton *)matchView {
if (!_matchView) {
_matchView = [UIButton buttonWithType:UIButtonTypeCustom];
[_matchView setBackgroundImage:[UIImage imageNamed:@"home_head_match"] forState:UIControlStateNormal];
[_matchView addTarget:self action:@selector(matchViewAction) forControlEvents:UIControlEventTouchUpInside];
_matchView.hidden = YES;
}
return _matchView;
}
- (UIImageView *)greenDot {
if (!_greenDot) {
_greenDot = [[UIImageView alloc] init];
UIImage *dotImage = [UIImage imageWithColor:[ThemeColor colorWithHexString:@"#82FBFF"] size:CGSizeMake(10, 10)];
dotImage = [dotImage setCornerWithRadius:dotImage.size.height/2.0 andSize:dotImage.size];
_greenDot.image = dotImage;
}
return _greenDot;
}
- (UILabel *)onlineNumLabel {
if (!_onlineNumLabel) {
_onlineNumLabel = [[UILabel alloc] init];
_onlineNumLabel.textColor = UIColor.whiteColor;
_onlineNumLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightMedium];
_onlineNumLabel.text = @"0人组队中";
}
return _onlineNumLabel;
}
- (NetImageView *)matchAvatar1 {
if (!_matchAvatar1) {
_matchAvatar1 = [[NetImageView alloc] init];
_matchAvatar1.clipsToBounds = YES;
_matchAvatar1.contentMode = UIViewContentModeScaleAspectFill;
_matchAvatar1.image = [UIImage imageNamed:@"home_match_avatar1"];
_matchAvatar1.layer.cornerRadius = 11;
}
return _matchAvatar1;
}
- (NetImageView *)matchAvatar2 {
if (!_matchAvatar2) {
_matchAvatar2 = [[NetImageView alloc] init];
_matchAvatar2.clipsToBounds = YES;
_matchAvatar2.contentMode = UIViewContentModeScaleAspectFill;
_matchAvatar2.image = [UIImage imageNamed:@"home_match_avatar2"];
_matchAvatar2.layer.cornerRadius = 18;
}
return _matchAvatar2;
}
- (NetImageView *)matchAvatar3 {
if (!_matchAvatar3) {
_matchAvatar3 = [[NetImageView alloc] init];
_matchAvatar3.clipsToBounds = YES;
_matchAvatar3.contentMode = UIViewContentModeScaleAspectFill;
_matchAvatar3.image = [UIImage imageNamed:@"home_match_avatar3"];
_matchAvatar3.layer.cornerRadius = 11;
}
return _matchAvatar3;
}
- (UIImageView *)hotView {
if (!_hotView) {
_hotView = [[UIImageView alloc] init];
_hotView.image = [UIImage imageNamed:@"home_hot_bg"];
_hotView.userInteractionEnabled = YES;
}
return _hotView;
}
- (UIImageView *)hotTextImageView {
if (!_hotTextImageView) {
_hotTextImageView = [[UIImageView alloc] init];
_hotTextImageView.contentMode = UIViewContentModeScaleAspectFit;
_hotTextImageView.image = [UIImage imageNamed:@"home_hot_text"];
}
return _hotTextImageView;
}
- (XPCycleVerticalView *)messageView {
if (!_messageView) {
_messageView = [[XPCycleVerticalView alloc] init];
_messageView.direction = XPCycleVerticalViewScrollDirectionUp;
}
return _messageView;
}
@end