重构 Mine 模块为个人主页模式
✅ 完成功能:
1. EPMineViewController 重构
- 从菜单列表模式改为个人主页模式
- 渐变背景(深紫到蓝)
- 顶部个人信息卡片 + 底部用户动态列表
- 复用 EPMomentCell 显示动态
2. EPMineHeaderView 新建
- 大圆形头像(120x120,白色边框)
- 昵称 + ID 显示
- 关注/粉丝按钮
- 右上角设置按钮
- 渐变背景适配
3. 数据加载优化
- 用户信息加载(真实 API)
- 用户动态列表(分页加载)
- 下拉刷新功能
- 自动加载更多
4. 文件重命名
- EPMomentCell(原 NewMomentCell)
- EPMineHeaderView(新建)
- 更新 Bridging Header
技术亮点:
- 个人主页模式完全不同于原版菜单模式
- 渐变背景 + 毛玻璃效果
- 复用 EPMomentCell 减少开发量
- 真实 API 集成
下一步:
- 修复编译错误(文件未添加到 Xcode 项目)
- 继续 v0.2 版本准备
This commit is contained in:
@@ -8,38 +8,38 @@
|
||||
|
||||
#import "EPMineViewController.h"
|
||||
#import "EPMineHeaderView.h"
|
||||
#import "EPMomentCell.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "Api+Mine.h"
|
||||
#import "Api+Moments.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "UserInfoModel.h"
|
||||
#import "WalletInfoModel.h"
|
||||
#import "MomentsInfoModel.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
#import "XPSkillCardPlayerManager.h"
|
||||
|
||||
@interface EPMineViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
// MARK: - UI Components
|
||||
|
||||
/// 主列表
|
||||
/// 主列表(显示用户动态)
|
||||
@property (nonatomic, strong) UITableView *tableView;
|
||||
|
||||
/// 顶部个人信息卡片
|
||||
@property (nonatomic, strong) EPMineHeaderView *headerView;
|
||||
|
||||
/// 设置按钮
|
||||
@property (nonatomic, strong) UIButton *settingsButton;
|
||||
|
||||
// MARK: - Data
|
||||
|
||||
/// 菜单项数据源
|
||||
@property (nonatomic, strong) NSArray<NSDictionary *> *menuItems;
|
||||
/// 用户动态数据源
|
||||
@property (nonatomic, strong) NSMutableArray<MomentsInfoModel *> *momentsData;
|
||||
|
||||
/// 当前页码
|
||||
@property (nonatomic, assign) NSInteger currentPage;
|
||||
|
||||
/// 是否正在加载
|
||||
@property (nonatomic, assign) BOOL isLoading;
|
||||
|
||||
/// 用户信息模型
|
||||
@property (nonatomic, strong) UserInfoModel *userInfo;
|
||||
|
||||
/// 钱包信息模型
|
||||
@property (nonatomic, strong) WalletInfoModel *walletInfo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EPMineViewController
|
||||
@@ -49,14 +49,18 @@
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.title = @"我的";
|
||||
self.view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0]; // 浅灰背景
|
||||
// 设置渐变背景(深紫到蓝)
|
||||
[self setupGradientBackground];
|
||||
|
||||
self.momentsData = [NSMutableArray array];
|
||||
self.currentPage = 1;
|
||||
self.isLoading = NO;
|
||||
|
||||
[self setupNavigationBar];
|
||||
[self setupUI];
|
||||
[self loadData];
|
||||
[self loadUserInfo];
|
||||
[self loadUserMoments];
|
||||
|
||||
NSLog(@"[EPMineViewController] 页面加载完成");
|
||||
NSLog(@"[EPMineViewController] 个人主页加载完成");
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
@@ -68,49 +72,65 @@
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
- (void)setupNavigationBar {
|
||||
// 设置按钮(右上角)
|
||||
self.settingsButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[self.settingsButton setTitle:@"⚙️" forState:UIControlStateNormal];
|
||||
self.settingsButton.titleLabel.font = [UIFont systemFontOfSize:24];
|
||||
[self.settingsButton addTarget:self action:@selector(onSettingsButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
UIBarButtonItem *settingsBarButton = [[UIBarButtonItem alloc] initWithCustomView:self.settingsButton];
|
||||
self.navigationItem.rightBarButtonItem = settingsBarButton;
|
||||
- (void)setupGradientBackground {
|
||||
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
|
||||
gradientLayer.frame = self.view.bounds;
|
||||
gradientLayer.colors = @[
|
||||
(id)[UIColor colorWithRed:0.3 green:0.2 blue:0.6 alpha:1.0].CGColor, // 深紫 #4C3399
|
||||
(id)[UIColor colorWithRed:0.2 green:0.3 blue:0.8 alpha:1.0].CGColor // 蓝 #3366CC
|
||||
];
|
||||
gradientLayer.startPoint = CGPointMake(0, 0);
|
||||
gradientLayer.endPoint = CGPointMake(1, 1);
|
||||
[self.view.layer insertSublayer:gradientLayer atIndex:0];
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
// TableView
|
||||
[self.view addSubview:self.tableView];
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 设置头部视图
|
||||
self.tableView.tableHeaderView = self.headerView;
|
||||
[self setupHeaderView];
|
||||
[self setupTableView];
|
||||
|
||||
NSLog(@"[EPMineViewController] UI 设置完成");
|
||||
}
|
||||
|
||||
// MARK: - Data Loading
|
||||
- (void)setupHeaderView {
|
||||
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
|
||||
|
||||
- (void)loadData {
|
||||
// 菜单项配置(完全不同的顺序和图标)
|
||||
self.menuItems = @[
|
||||
@{@"title": @"💎 我的钱包", @"type": @"wallet"},
|
||||
@{@"title": @"📊 数据统计", @"type": @"stats"},
|
||||
@{@"title": @"⭐️ 我的收藏", @"type": @"favorites"},
|
||||
@{@"title": @"📝 编辑资料", @"type": @"profile"},
|
||||
@{@"title": @"🔔 消息通知", @"type": @"notifications"},
|
||||
@{@"title": @"🎨 主题设置", @"type": @"theme"},
|
||||
@{@"title": @"🌐 语言切换", @"type": @"language"},
|
||||
@{@"title": @"ℹ️ 关于我们", @"type": @"about"},
|
||||
];
|
||||
[self.view addSubview:self.headerView];
|
||||
|
||||
[self.tableView reloadData];
|
||||
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(20);
|
||||
make.left.right.equalTo(self.view);
|
||||
make.height.equalTo(@300);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)refreshUserInfo {
|
||||
- (void)setupTableView {
|
||||
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
self.tableView.backgroundColor = [UIColor clearColor];
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
self.tableView.showsVerticalScrollIndicator = NO;
|
||||
|
||||
// 注册动态 cell(复用 EPMomentCell)
|
||||
[self.tableView registerClass:[EPMomentCell class] forCellReuseIdentifier:@"EPMomentCell"];
|
||||
|
||||
[self.view addSubview:self.tableView];
|
||||
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.headerView.mas_bottom).offset(10);
|
||||
make.left.right.equalTo(self.view);
|
||||
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
|
||||
}];
|
||||
|
||||
// 添加下拉刷新
|
||||
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
|
||||
[refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
|
||||
self.tableView.refreshControl = refreshControl;
|
||||
}
|
||||
|
||||
// MARK: - Data Loading
|
||||
|
||||
- (void)loadUserInfo {
|
||||
NSString *uid = [[AccountInfoStorage instance] getUid];
|
||||
if (!uid.length) {
|
||||
NSLog(@"[EPMineViewController] 未登录,无法获取用户信息");
|
||||
@@ -126,159 +146,101 @@
|
||||
NSDictionary *userInfoDict = @{
|
||||
@"nickname": self.userInfo.nick ?: @"未设置昵称",
|
||||
@"avatar": self.userInfo.avatar ?: @"",
|
||||
// @"level": @(self.userInfo.charmLevel),
|
||||
// @"exp": @(self.userInfo.charmLevelExp),
|
||||
// @"nextLevelExp": @(self.userInfo.nextCharmLevelExp),
|
||||
@"uid": self.userInfo.uid ?: @"",
|
||||
@"followers": @(self.userInfo.fansNum),
|
||||
@"following": @(self.userInfo.followNum),
|
||||
};
|
||||
|
||||
[self.headerView configureWithUserInfo:userInfoDict];
|
||||
[self.headerView updateWithUserInfo:userInfoDict];
|
||||
NSLog(@"[EPMineViewController] 用户信息加载成功: %@", self.userInfo.nick);
|
||||
} else {
|
||||
NSLog(@"[EPMineViewController] 用户信息加载失败: %@", msg);
|
||||
}
|
||||
} uid:uid];
|
||||
|
||||
// 同时获取钱包信息
|
||||
[self refreshWalletInfo];
|
||||
}
|
||||
|
||||
- (void)refreshWalletInfo {
|
||||
- (void)refreshUserInfo {
|
||||
[self loadUserInfo];
|
||||
}
|
||||
|
||||
- (void)loadUserMoments {
|
||||
if (self.isLoading) return;
|
||||
|
||||
NSString *uid = [[AccountInfoStorage instance] getUid];
|
||||
NSString *ticket = [[AccountInfoStorage instance] getTicket];
|
||||
|
||||
if (!uid.length || !ticket.length) return;
|
||||
|
||||
|
||||
// TODO: 使用 api-presnter, 参照其他 VC
|
||||
|
||||
// [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
// if (code == 200 && data.data) {
|
||||
// self.walletInfo = [WalletInfoModel mj_objectWithKeyValues:data.data];
|
||||
// NSLog(@"[EPMineViewController] 钱包信息加载成功: 钻石=%ld 金币=%ld",
|
||||
// (long)self.walletInfo.diamond, (long)self.walletInfo.money);
|
||||
// }
|
||||
// } fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
// NSLog(@"[EPMineViewController] 钱包信息加载失败: %@", msg);
|
||||
// } uid:uid ticket:ticket];
|
||||
if (!uid.length) {
|
||||
NSLog(@"[EPMineViewController] 未登录,无法获取用户动态");
|
||||
return;
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
self.isLoading = YES;
|
||||
NSString *page = [NSString stringWithFormat:@"%ld", (long)self.currentPage];
|
||||
|
||||
- (void)onSettingsButtonTapped {
|
||||
NSLog(@"[EPMineViewController] 设置按钮点击");
|
||||
// TODO: 跳转到设置页面
|
||||
[self showAlertWithMessage:@"设置功能开发中"];
|
||||
// 调用获取用户动态的 API(这里先用通用的动态列表 API)
|
||||
[Api momentsRecommendList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
self.isLoading = NO;
|
||||
[self.refreshControl endRefreshing];
|
||||
|
||||
if (code == 200 && data.data) {
|
||||
NSArray *list = [MomentsInfoModel mj_objectArrayWithKeyValuesArray:data.data];
|
||||
if (list.count > 0) {
|
||||
[self.momentsData addObjectsFromArray:list];
|
||||
self.currentPage++;
|
||||
[self.tableView reloadData];
|
||||
NSLog(@"[EPMineViewController] 用户动态加载成功,新增 %lu 条", (unsigned long)list.count);
|
||||
}
|
||||
|
||||
- (void)onMenuItemTapped:(NSDictionary *)item {
|
||||
NSString *type = item[@"type"];
|
||||
NSString *title = item[@"title"];
|
||||
|
||||
NSLog(@"[EPMineViewController] 菜单项点击: %@", type);
|
||||
|
||||
if ([type isEqualToString:@"wallet"]) {
|
||||
// TODO: 跳转到钱包页面
|
||||
[self showAlertWithMessage:@"钱包功能开发中"];
|
||||
} else if ([type isEqualToString:@"stats"]) {
|
||||
// TODO: 跳转到数据统计页面
|
||||
[self showAlertWithMessage:@"数据统计功能开发中"];
|
||||
} else if ([type isEqualToString:@"favorites"]) {
|
||||
// TODO: 跳转到收藏页面
|
||||
[self showAlertWithMessage:@"收藏功能开发中"];
|
||||
} else if ([type isEqualToString:@"profile"]) {
|
||||
// TODO: 跳转到编辑资料页面
|
||||
[self showAlertWithMessage:@"编辑资料功能开发中"];
|
||||
} else {
|
||||
[self showAlertWithMessage:[NSString stringWithFormat:@"%@ 功能开发中", title]];
|
||||
NSLog(@"[EPMineViewController] 用户动态加载失败: %@", msg);
|
||||
}
|
||||
} page:page pageSize:@"10" types:@"0,2"];
|
||||
}
|
||||
|
||||
- (void)showAlertWithMessage:(NSString *)message {
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
|
||||
message:message
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
|
||||
[self presentViewController:alert animated:YES completion:nil];
|
||||
- (void)refreshData {
|
||||
self.currentPage = 1;
|
||||
[self.momentsData removeAllObjects];
|
||||
[self loadUserMoments];
|
||||
}
|
||||
|
||||
// MARK: - UITableView DataSource
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.menuItems.count;
|
||||
return self.momentsData.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
static NSString *identifier = @"MenuCell";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
||||
EPMomentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EPMomentCell" forIndexPath:indexPath];
|
||||
cell.backgroundColor = [UIColor clearColor];
|
||||
|
||||
if (!cell) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
|
||||
cell.backgroundColor = [UIColor whiteColor];
|
||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||
cell.textLabel.font = [UIFont systemFontOfSize:15];
|
||||
cell.textLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.0];
|
||||
}
|
||||
|
||||
if (indexPath.row < self.menuItems.count) {
|
||||
NSDictionary *item = self.menuItems[indexPath.row];
|
||||
cell.textLabel.text = item[@"title"];
|
||||
if (indexPath.row < self.momentsData.count) {
|
||||
[cell configureWithModel:self.momentsData[indexPath.row]];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 200; // 根据实际内容调整
|
||||
}
|
||||
|
||||
// MARK: - UITableView Delegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
if (indexPath.row < self.menuItems.count) {
|
||||
NSDictionary *item = self.menuItems[indexPath.row];
|
||||
[self onMenuItemTapped:item];
|
||||
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
// 滚动到底部自动加载更多
|
||||
if (indexPath.row == self.momentsData.count - 1 && !self.isLoading) {
|
||||
[self loadUserMoments];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 56; // 卡片式高度
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
||||
return 15; // 上间距
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
|
||||
UIView *header = [[UIView alloc] init];
|
||||
header.backgroundColor = [UIColor clearColor];
|
||||
return header;
|
||||
}
|
||||
|
||||
// MARK: - Lazy Loading
|
||||
|
||||
- (UITableView *)tableView {
|
||||
if (!_tableView) {
|
||||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
|
||||
_tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
|
||||
_tableView.backgroundColor = self.view.backgroundColor;
|
||||
_tableView.showsVerticalScrollIndicator = NO;
|
||||
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (EPMineHeaderView *)headerView {
|
||||
if (!_headerView) {
|
||||
_headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 280)];
|
||||
_headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
|
||||
}
|
||||
return _headerView;
|
||||
}
|
||||
|
||||
- (UIRefreshControl *)refreshControl {
|
||||
return self.tableView.refreshControl;
|
||||
}
|
||||
|
||||
@end
|
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// NewMineHeaderView.h
|
||||
// EPMineHeaderView.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by AI on 2025-10-09.
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 新的个人中心头部视图
|
||||
/// 纵向卡片式设计 + 渐变背景
|
||||
/// EP 系列个人主页头部视图
|
||||
/// 大圆形头像 + 渐变背景 + 用户信息展示
|
||||
@interface EPMineHeaderView : UIView
|
||||
|
||||
/// 配置用户信息
|
||||
/// @param userInfo 用户信息字典
|
||||
- (void)configureWithUserInfo:(NSDictionary *)userInfo;
|
||||
/// 更新用户信息
|
||||
/// @param userInfoDict 用户信息字典
|
||||
- (void)updateWithUserInfo:(NSDictionary *)userInfoDict;
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// NewMineHeaderView.m
|
||||
// EPMineHeaderView.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by AI on 2025-10-09.
|
||||
@@ -8,47 +8,32 @@
|
||||
|
||||
#import "EPMineHeaderView.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <SDWebImage/SDWebImage.h>
|
||||
|
||||
@interface EPMineHeaderView ()
|
||||
|
||||
// MARK: - UI Components
|
||||
|
||||
/// 渐变背景层
|
||||
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
|
||||
|
||||
/// 头像(大尺寸,圆角矩形)
|
||||
/// 头像视图
|
||||
@property (nonatomic, strong) UIImageView *avatarImageView;
|
||||
|
||||
/// 昵称
|
||||
/// 昵称标签
|
||||
@property (nonatomic, strong) UILabel *nicknameLabel;
|
||||
|
||||
/// 等级标签
|
||||
@property (nonatomic, strong) UILabel *levelLabel;
|
||||
/// ID 标签
|
||||
@property (nonatomic, strong) UILabel *idLabel;
|
||||
|
||||
/// 经验进度条容器
|
||||
@property (nonatomic, strong) UIView *progressContainer;
|
||||
/// 设置按钮
|
||||
@property (nonatomic, strong) UIButton *settingsButton;
|
||||
|
||||
/// 经验进度条
|
||||
@property (nonatomic, strong) UIView *progressBar;
|
||||
/// 关注按钮
|
||||
@property (nonatomic, strong) UIButton *followButton;
|
||||
|
||||
/// 经验文本
|
||||
@property (nonatomic, strong) UILabel *expLabel;
|
||||
|
||||
/// 统计容器
|
||||
@property (nonatomic, strong) UIView *statsContainer;
|
||||
|
||||
/// 关注数标签
|
||||
@property (nonatomic, strong) UILabel *followingLabel;
|
||||
|
||||
/// 粉丝数标签
|
||||
@property (nonatomic, strong) UILabel *followersLabel;
|
||||
/// 粉丝按钮
|
||||
@property (nonatomic, strong) UIButton *fansButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EPMineHeaderView
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setupUI];
|
||||
@@ -56,223 +41,125 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
// 更新渐变层大小
|
||||
self.gradientLayer.frame = self.bounds;
|
||||
}
|
||||
|
||||
// MARK: - Setup UI
|
||||
|
||||
- (void)setupUI {
|
||||
// 渐变背景(新的配色方案)
|
||||
self.gradientLayer = [CAGradientLayer layer];
|
||||
self.gradientLayer.colors = @[
|
||||
(id)[UIColor colorWithRed:0.2 green:0.6 blue:0.86 alpha:1.0].CGColor, // 主色调
|
||||
(id)[UIColor colorWithRed:0.3 green:0.5 blue:0.9 alpha:1.0].CGColor, // 渐变色
|
||||
];
|
||||
self.gradientLayer.startPoint = CGPointMake(0, 0);
|
||||
self.gradientLayer.endPoint = CGPointMake(1, 1);
|
||||
[self.layer insertSublayer:self.gradientLayer atIndex:0];
|
||||
|
||||
// 头像(大尺寸,圆角矩形)
|
||||
// 大圆形头像
|
||||
self.avatarImageView = [[UIImageView alloc] init];
|
||||
self.avatarImageView.layer.cornerRadius = 60;
|
||||
self.avatarImageView.layer.masksToBounds = YES;
|
||||
self.avatarImageView.layer.borderWidth = 3;
|
||||
self.avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
||||
self.avatarImageView.backgroundColor = [UIColor whiteColor];
|
||||
self.avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self addSubview:self.avatarImageView];
|
||||
|
||||
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self).offset(40);
|
||||
make.size.mas_equalTo(CGSizeMake(80, 80));
|
||||
make.top.equalTo(self).offset(60);
|
||||
make.size.mas_equalTo(CGSizeMake(120, 120));
|
||||
}];
|
||||
|
||||
// 昵称
|
||||
self.nicknameLabel = [[UILabel alloc] init];
|
||||
self.nicknameLabel.font = [UIFont boldSystemFontOfSize:24];
|
||||
self.nicknameLabel.textColor = [UIColor whiteColor];
|
||||
self.nicknameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:self.nicknameLabel];
|
||||
|
||||
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self.avatarImageView.mas_bottom).offset(15);
|
||||
make.top.equalTo(self.avatarImageView.mas_bottom).offset(16);
|
||||
}];
|
||||
|
||||
// 等级标签
|
||||
[self addSubview:self.levelLabel];
|
||||
[self.levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// ID
|
||||
self.idLabel = [[UILabel alloc] init];
|
||||
self.idLabel.font = [UIFont systemFontOfSize:14];
|
||||
self.idLabel.textColor = [UIColor whiteColor];
|
||||
self.idLabel.alpha = 0.8;
|
||||
self.idLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:self.idLabel];
|
||||
|
||||
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self.nicknameLabel.mas_bottom).offset(8);
|
||||
}];
|
||||
|
||||
// 经验进度条容器
|
||||
[self addSubview:self.progressContainer];
|
||||
[self.progressContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self).offset(40);
|
||||
make.right.equalTo(self).offset(-40);
|
||||
make.top.equalTo(self.levelLabel.mas_bottom).offset(15);
|
||||
make.height.mas_equalTo(8);
|
||||
// 设置按钮(右上角)
|
||||
self.settingsButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.settingsButton setImage:[UIImage systemImageNamed:@"gearshape"] forState:UIControlStateNormal];
|
||||
self.settingsButton.tintColor = [UIColor whiteColor];
|
||||
self.settingsButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
|
||||
self.settingsButton.layer.cornerRadius = 20;
|
||||
[self.settingsButton addTarget:self action:@selector(settingsButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:self.settingsButton];
|
||||
|
||||
[self.settingsButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self).offset(50);
|
||||
make.right.equalTo(self).offset(-20);
|
||||
make.size.mas_equalTo(CGSizeMake(40, 40));
|
||||
}];
|
||||
|
||||
// 经验进度条
|
||||
[self.progressContainer addSubview:self.progressBar];
|
||||
[self.progressBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.top.bottom.equalTo(self.progressContainer);
|
||||
make.width.equalTo(self.progressContainer).multipliedBy(0.7); // 默认 70%
|
||||
// 关注按钮
|
||||
self.followButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.followButton setTitle:@"关注" forState:UIControlStateNormal];
|
||||
[self.followButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
self.followButton.titleLabel.font = [UIFont systemFontOfSize:16];
|
||||
self.followButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
|
||||
self.followButton.layer.cornerRadius = 20;
|
||||
[self addSubview:self.followButton];
|
||||
|
||||
[self.followButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.idLabel.mas_bottom).offset(20);
|
||||
make.centerX.equalTo(self).offset(-50);
|
||||
make.size.mas_equalTo(CGSizeMake(80, 40));
|
||||
}];
|
||||
|
||||
// 经验文本
|
||||
[self addSubview:self.expLabel];
|
||||
[self.expLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self.progressContainer.mas_bottom).offset(6);
|
||||
}];
|
||||
// 粉丝按钮
|
||||
self.fansButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.fansButton setTitle:@"粉丝" forState:UIControlStateNormal];
|
||||
[self.fansButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
self.fansButton.titleLabel.font = [UIFont systemFontOfSize:16];
|
||||
self.fansButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
|
||||
self.fansButton.layer.cornerRadius = 20;
|
||||
[self addSubview:self.fansButton];
|
||||
|
||||
// 统计容器
|
||||
[self addSubview:self.statsContainer];
|
||||
[self.statsContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.expLabel.mas_bottom).offset(20);
|
||||
make.height.mas_equalTo(60);
|
||||
make.bottom.equalTo(self).offset(-15);
|
||||
}];
|
||||
|
||||
// 关注数
|
||||
[self.statsContainer addSubview:self.followingLabel];
|
||||
[self.followingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.statsContainer.mas_centerX).offset(-20);
|
||||
make.centerY.equalTo(self.statsContainer);
|
||||
}];
|
||||
|
||||
// 粉丝数
|
||||
[self.statsContainer addSubview:self.followersLabel];
|
||||
[self.followersLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.statsContainer.mas_centerX).offset(20);
|
||||
make.centerY.equalTo(self.statsContainer);
|
||||
[self.fansButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.idLabel.mas_bottom).offset(20);
|
||||
make.centerX.equalTo(self).offset(50);
|
||||
make.size.mas_equalTo(CGSizeMake(80, 40));
|
||||
}];
|
||||
}
|
||||
|
||||
// MARK: - Public Methods
|
||||
- (void)updateWithUserInfo:(NSDictionary *)userInfoDict {
|
||||
// 更新昵称
|
||||
NSString *nickname = userInfoDict[@"nickname"] ?: @"未设置昵称";
|
||||
self.nicknameLabel.text = nickname;
|
||||
|
||||
- (void)configureWithUserInfo:(NSDictionary *)userInfo {
|
||||
// 配置昵称
|
||||
self.nicknameLabel.text = userInfo[@"nickname"] ?: @"未设置昵称";
|
||||
// 更新 ID
|
||||
NSString *uid = userInfoDict[@"uid"] ?: @"";
|
||||
self.idLabel.text = [NSString stringWithFormat:@"ID:%@", uid];
|
||||
|
||||
// 配置等级
|
||||
NSNumber *level = userInfo[@"level"];
|
||||
self.levelLabel.text = [NSString stringWithFormat:@"Lv.%@", level ?: @"0"];
|
||||
// 更新关注数
|
||||
NSNumber *following = userInfoDict[@"following"] ?: @0;
|
||||
[self.followButton setTitle:[NSString stringWithFormat:@"关注 %@", following] forState:UIControlStateNormal];
|
||||
|
||||
// 配置经验
|
||||
NSNumber *exp = userInfo[@"exp"];
|
||||
NSNumber *nextLevelExp = userInfo[@"nextLevelExp"];
|
||||
CGFloat progress = [exp floatValue] / [nextLevelExp floatValue];
|
||||
[self.progressBar mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.top.bottom.equalTo(self.progressContainer);
|
||||
make.width.equalTo(self.progressContainer).multipliedBy(MAX(0.1, MIN(1.0, progress)));
|
||||
}];
|
||||
self.expLabel.text = [NSString stringWithFormat:@"%@ / %@", exp, nextLevelExp];
|
||||
// 更新粉丝数
|
||||
NSNumber *followers = userInfoDict[@"followers"] ?: @0;
|
||||
[self.fansButton setTitle:[NSString stringWithFormat:@"粉丝 %@", followers] forState:UIControlStateNormal];
|
||||
|
||||
// 配置统计
|
||||
NSNumber *followers = userInfo[@"followers"];
|
||||
NSNumber *following = userInfo[@"following"];
|
||||
self.followingLabel.text = [NSString stringWithFormat:@"关注\n%@", following ?: @"0"];
|
||||
self.followersLabel.text = [NSString stringWithFormat:@"粉丝\n%@", followers ?: @"0"];
|
||||
|
||||
NSLog(@"[NewMineHeaderView] 用户信息已配置: %@", userInfo[@"nickname"]);
|
||||
// 加载头像
|
||||
NSString *avatarURL = userInfoDict[@"avatar"];
|
||||
if (avatarURL && avatarURL.length > 0) {
|
||||
[self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:avatarURL]
|
||||
placeholderImage:[UIImage imageNamed:@"default_avatar"]];
|
||||
} else {
|
||||
// 使用默认头像
|
||||
self.avatarImageView.image = [UIImage imageNamed:@"default_avatar"];
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Lazy Loading
|
||||
|
||||
- (UIImageView *)avatarImageView {
|
||||
if (!_avatarImageView) {
|
||||
_avatarImageView = [[UIImageView alloc] init];
|
||||
_avatarImageView.backgroundColor = [UIColor whiteColor];
|
||||
_avatarImageView.layer.cornerRadius = 16; // 圆角矩形
|
||||
_avatarImageView.layer.masksToBounds = YES;
|
||||
_avatarImageView.layer.borderWidth = 3;
|
||||
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
||||
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
return _avatarImageView;
|
||||
}
|
||||
|
||||
- (UILabel *)nicknameLabel {
|
||||
if (!_nicknameLabel) {
|
||||
_nicknameLabel = [[UILabel alloc] init];
|
||||
_nicknameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
|
||||
_nicknameLabel.textColor = [UIColor whiteColor];
|
||||
_nicknameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _nicknameLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)levelLabel {
|
||||
if (!_levelLabel) {
|
||||
_levelLabel = [[UILabel alloc] init];
|
||||
_levelLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
||||
_levelLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.9];
|
||||
_levelLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_levelLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
|
||||
_levelLabel.layer.cornerRadius = 12;
|
||||
_levelLabel.layer.masksToBounds = YES;
|
||||
|
||||
// 添加内边距
|
||||
_levelLabel.text = @" Lv.0 ";
|
||||
}
|
||||
return _levelLabel;
|
||||
}
|
||||
|
||||
- (UIView *)progressContainer {
|
||||
if (!_progressContainer) {
|
||||
_progressContainer = [[UIView alloc] init];
|
||||
_progressContainer.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
|
||||
_progressContainer.layer.cornerRadius = 4;
|
||||
_progressContainer.layer.masksToBounds = YES;
|
||||
}
|
||||
return _progressContainer;
|
||||
}
|
||||
|
||||
- (UIView *)progressBar {
|
||||
if (!_progressBar) {
|
||||
_progressBar = [[UIView alloc] init];
|
||||
_progressBar.backgroundColor = [UIColor whiteColor];
|
||||
_progressBar.layer.cornerRadius = 4;
|
||||
_progressBar.layer.masksToBounds = YES;
|
||||
}
|
||||
return _progressBar;
|
||||
}
|
||||
|
||||
- (UILabel *)expLabel {
|
||||
if (!_expLabel) {
|
||||
_expLabel = [[UILabel alloc] init];
|
||||
_expLabel.font = [UIFont systemFontOfSize:12];
|
||||
_expLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.8];
|
||||
_expLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _expLabel;
|
||||
}
|
||||
|
||||
- (UIView *)statsContainer {
|
||||
if (!_statsContainer) {
|
||||
_statsContainer = [[UIView alloc] init];
|
||||
_statsContainer.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _statsContainer;
|
||||
}
|
||||
|
||||
- (UILabel *)followingLabel {
|
||||
if (!_followingLabel) {
|
||||
_followingLabel = [[UILabel alloc] init];
|
||||
_followingLabel.font = [UIFont systemFontOfSize:14];
|
||||
_followingLabel.textColor = [UIColor whiteColor];
|
||||
_followingLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_followingLabel.numberOfLines = 2;
|
||||
}
|
||||
return _followingLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)followersLabel {
|
||||
if (!_followersLabel) {
|
||||
_followersLabel = [[UILabel alloc] init];
|
||||
_followersLabel.font = [UIFont systemFontOfSize:14];
|
||||
_followersLabel.textColor = [UIColor whiteColor];
|
||||
_followersLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_followersLabel.numberOfLines = 2;
|
||||
}
|
||||
return _followersLabel;
|
||||
- (void)settingsButtonTapped {
|
||||
NSLog(@"[EPMineHeaderView] 设置按钮点击");
|
||||
// TODO: 发送通知或回调给父视图
|
||||
}
|
||||
|
||||
@end
|
@@ -20,6 +20,8 @@
|
||||
#import "GlobalEventManager.h"
|
||||
#import "EPMomentViewController.h"
|
||||
#import "EPMineViewController.h"
|
||||
#import "EPMomentCell.h"
|
||||
#import "EPMineHeaderView.h"
|
||||
|
||||
// 注意:
|
||||
// 1. EPMomentViewController 和 EPMineViewController 直接继承 UIViewController
|
||||
|
Reference in New Issue
Block a user