feat: 更新 EPEditSettingViewController 以增强用户信息管理功能
主要变更: 1. 在 EPEditSettingViewController 中添加了用户头像和相机图标的布局,提升用户界面友好性。 2. 引入 EPMineAPIHelper 以支持头像更新功能,简化 API 调用。 3. 优化了导航栏的显示和隐藏逻辑,确保用户体验流畅。 4. 更新了 UITableView 的数据源和布局,确保信息展示清晰。 此更新旨在提升用户体验,简化用户信息的管理和更新流程。
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self setupUI];
|
||||
|
||||
NSLog(@"[EPMineViewController] viewDidLoad 完成");
|
||||
@@ -49,10 +48,7 @@
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
// 隐藏导航栏
|
||||
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
||||
|
||||
// 每次显示时加载最新数据
|
||||
[self loadUserDetailInfo];
|
||||
}
|
||||
@@ -60,8 +56,13 @@
|
||||
// MARK: - Setup
|
||||
|
||||
- (void)setupUI {
|
||||
// 背景渐变色
|
||||
self.view.backgroundColor = [UIColor colorWithRed:0.047 green:0.020 blue:0.153 alpha:1.0]; // #0C0527
|
||||
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:kImage(@"vc_bg")];
|
||||
bgImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
bgImageView.clipsToBounds = YES;
|
||||
[self.view addSubview:bgImageView];
|
||||
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.view);
|
||||
}];
|
||||
|
||||
[self setupHeaderView];
|
||||
[self setupMomentListView];
|
||||
@@ -73,19 +74,25 @@
|
||||
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectZero];
|
||||
[self.view addSubview:self.headerView];
|
||||
|
||||
// 使用约束布局
|
||||
self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[self.headerView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
||||
[self.headerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||
[self.headerView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||||
[self.headerView.heightAnchor constraintEqualToConstant:320]
|
||||
]];
|
||||
// 使用 Masonry 约束布局
|
||||
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view);
|
||||
make.leading.mas_equalTo(self.view);
|
||||
make.trailing.mas_equalTo(self.view);
|
||||
make.height.mas_equalTo(kGetScaleWidth(320));
|
||||
}];
|
||||
|
||||
// 监听设置按钮点击事件
|
||||
// 设置按钮点击回调
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.headerView.onSettingsButtonTapped = ^{
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
[self openSettings];
|
||||
};
|
||||
|
||||
// 监听头像更新事件
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(openSettings)
|
||||
name:@"EPMineHeaderSettingsButtonTapped"
|
||||
selector:@selector(onAvatarUpdated:)
|
||||
name:@"EPEditSettingAvatarUpdated"
|
||||
object:nil];
|
||||
}
|
||||
|
||||
@@ -93,14 +100,13 @@
|
||||
self.momentListView = [[EPMomentListView alloc] initWithFrame:CGRectZero];
|
||||
[self.view addSubview:self.momentListView];
|
||||
|
||||
// 使用约束布局
|
||||
self.momentListView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[self.momentListView.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor],
|
||||
[self.momentListView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||
[self.momentListView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||||
[self.momentListView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
|
||||
]];
|
||||
// 使用 Masonry 约束布局
|
||||
[self.momentListView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.headerView.mas_bottom);
|
||||
make.bottom.mas_equalTo(self.view);
|
||||
make.leading.mas_equalTo(self.view);
|
||||
make.trailing.mas_equalTo(self.view);
|
||||
}];
|
||||
}
|
||||
|
||||
// MARK: - Data Loading
|
||||
@@ -172,13 +178,37 @@
|
||||
// MARK: - Actions
|
||||
|
||||
- (void)openSettings {
|
||||
// 隐藏返回按钮文字,只保留白色箭头
|
||||
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@""
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:nil
|
||||
action:nil];
|
||||
|
||||
EPEditSettingViewController *settingsVC = [[EPEditSettingViewController alloc] init];
|
||||
// 传递用户信息到设置页面
|
||||
if (self.userInfo) {
|
||||
[settingsVC updateWithUserInfo:self.userInfo];
|
||||
}
|
||||
[self.navigationController pushViewController:settingsVC animated:YES];
|
||||
NSLog(@"[EPMineViewController] 打开设置页面");
|
||||
NSLog(@"[EPMineViewController] 打开设置页面,已传递用户信息");
|
||||
}
|
||||
|
||||
- (void)onAvatarUpdated:(NSNotification *)notification {
|
||||
NSString *avatarUrl = notification.userInfo[@"avatarUrl"];
|
||||
if (avatarUrl && self.userInfo) {
|
||||
// 更新本地用户信息
|
||||
self.userInfo.avatar = avatarUrl;
|
||||
|
||||
// 更新 UI 显示
|
||||
[self updateHeaderWithUserInfo:self.userInfo];
|
||||
|
||||
NSLog(@"[EPMineViewController] 头像已更新: %@", avatarUrl);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
// 只移除头像更新通知的观察者,设置按钮现在使用 block 回调
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"EPEditSettingAvatarUpdated" object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user