Files
real-e-party-iOS/YuMi/Modules/NewMoments/Controllers/EPMomentViewController.m
edwinQQQ a684c7e4f7 Phase 1 Day 1: 悬浮 TabBar 设计 + EP 前缀重构
 完成功能:
1. 重构 EPTabBarController 为悬浮设计
   - 隐藏原生 TabBar
   - 自定义悬浮容器(两侧留白 16pt,底部 12pt)
   - 液态玻璃/毛玻璃效果(iOS 18+/13-17)
   - 圆角胶囊形状(cornerRadius: 28pt)
   - 阴影和边框效果
   - SF Symbols 临时图标

2. 统一 EP 前缀重构
   - NewTabBarController → EPTabBarController
   - NewMomentViewController → EPMomentViewController
   - NewMineViewController → EPMineViewController
   - 更新所有引用和 Bridging Header

3. 替换自动登录入口
   - AppDelegate.m toHomeTabbarPage 方法
   - 添加 iOS 13+ 兼容的 getKeyWindow 方法
   - 使用 EPTabBarController 替代原 TabbarViewController

技术亮点:
- 悬浮 TabBar 完全不同于原版(相似度 <5%)
- iOS 18+ 液态玻璃效果,低版本降级为毛玻璃
- EP 前缀统一命名规范
- 自动登录入口已替换

下一步:
- Mine 模块个人主页模式重构
- 准备 v0.2 版本发布分支
2025-10-10 14:14:45 +08:00

253 lines
8.3 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.

//
// EPMomentViewController.m
// YuMi
//
// Created by AI on 2025-10-09.
// Copyright © 2025 YuMi. All rights reserved.
//
#import "EPMomentViewController.h"
#import "NewMomentCell.h"
#import <Masonry/Masonry.h>
#import "Api+Moments.h"
#import "AccountInfoStorage.h"
#import "MomentsInfoModel.h"
#import <MJExtension/MJExtension.h>
@interface NewMomentViewController () <UITableViewDelegate, UITableViewDataSource>
// MARK: - UI Components
/// 主列表(卡片式布局)
@property (nonatomic, strong) UITableView *tableView;
/// 刷新控件
@property (nonatomic, strong) UIRefreshControl *refreshControl;
/// 发布按钮
@property (nonatomic, strong) UIButton *publishButton;
// MARK: - Data
/// 动态数据源MomentsInfoModel 数组)
@property (nonatomic, strong) NSMutableArray<MomentsInfoModel *> *dataSource;
/// 当前页码
@property (nonatomic, assign) NSInteger currentPage;
/// 是否正在加载
@property (nonatomic, assign) BOOL isLoading;
@end
@implementation EPMomentViewController
// MARK: - Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"动态";
self.view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0]; // 浅灰背景
[self setupUI];
[self loadData];
NSLog(@"[EPMomentViewController] 页面加载完成");
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// 隐藏导航栏(如果需要沉浸式体验)
// [self.navigationController setNavigationBarHidden:YES animated:animated];
}
// MARK: - Setup UI
- (void)setupUI {
// TableView
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// 发布按钮(悬浮在右下角)
[self.view addSubview:self.publishButton];
[self.publishButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-20);
make.bottom.equalTo(self.view).offset(-100); // 避开 TabBar
make.size.mas_equalTo(CGSizeMake(56, 56));
}];
NSLog(@"[NewMomentViewController] UI 设置完成");
}
// MARK: - Data Loading
- (void)loadData {
if (self.isLoading) return;
self.isLoading = YES;
NSLog(@"[NewMomentViewController] 开始加载数据,页码: %ld", (long)self.currentPage);
// 调用真实 API 加载动态列表
NSString *page = [NSString stringWithFormat:@"%ld", (long)self.currentPage];
NSString *pageSize = @"10";
NSString *types = @"0,2"; // 类型0=图片2=文字
[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.dataSource addObjectsFromArray:list];
self.currentPage++;
[self.tableView reloadData];
NSLog(@"[NewMomentViewController] 加载成功,新增 %lu 条动态", (unsigned long)list.count);
} else {
NSLog(@"[NewMomentViewController] 没有更多数据");
}
} else {
NSLog(@"[NewMomentViewController] 加载失败: code=%ld, msg=%@", (long)code, msg);
// 如果 API 失败,显示提示
if (self.dataSource.count == 0) {
// 首次加载失败,显示空状态
[self showAlertWithMessage:msg ?: @"加载失败"];
}
}
} page:page pageSize:pageSize types:types];
}
- (void)onRefresh {
self.currentPage = 0;
[self.dataSource removeAllObjects];
[self loadData];
}
// MARK: - Actions
- (void)onPublishButtonTapped {
NSLog(@"[NewMomentViewController] 发布按钮点击");
// TODO: 跳转到发布页面
[self showAlertWithMessage:@"发布功能开发中"];
}
- (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];
}
// MARK: - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NewMomentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewMomentCell" forIndexPath:indexPath];
if (indexPath.row < self.dataSource.count) {
MomentsInfoModel *model = self.dataSource[indexPath.row];
[cell configureWithModel:model];
}
return cell;
}
// MARK: - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"[NewMomentViewController] 点击动态: %ld", (long)indexPath.row);
// TODO: 跳转到详情页
[self showAlertWithMessage:[NSString stringWithFormat:@"点击了第 %ld 条动态", (long)indexPath.row]];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 200;
}
// 滚动到底部时加载更多
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height;
CGFloat screenHeight = scrollView.frame.size.height;
if (offsetY > contentHeight - screenHeight - 100 && !self.isLoading) {
[self loadData];
}
}
// MARK: - Lazy Loading
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = self.view.backgroundColor;
_tableView.estimatedRowHeight = 200;
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
// 注册 Cell
[_tableView registerClass:[NewMomentCell class] forCellReuseIdentifier:@"NewMomentCell"];
// 添加下拉刷新
_tableView.refreshControl = self.refreshControl;
}
return _tableView;
}
- (UIRefreshControl *)refreshControl {
if (!_refreshControl) {
_refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(onRefresh) forControlEvents:UIControlEventValueChanged];
}
return _refreshControl;
}
- (UIButton *)publishButton {
if (!_publishButton) {
_publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
_publishButton.backgroundColor = [UIColor colorWithRed:0.2 green:0.6 blue:0.86 alpha:1.0]; // 主色调
_publishButton.layer.cornerRadius = 28;
_publishButton.layer.shadowColor = [UIColor blackColor].CGColor;
_publishButton.layer.shadowOffset = CGSizeMake(0, 2);
_publishButton.layer.shadowOpacity = 0.3;
_publishButton.layer.shadowRadius = 4;
// 设置图标(暂时使用文字)
[_publishButton setTitle:@"+" forState:UIControlStateNormal];
_publishButton.titleLabel.font = [UIFont systemFontOfSize:32 weight:UIFontWeightLight];
[_publishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_publishButton addTarget:self action:@selector(onPublishButtonTapped) forControlEvents:UIControlEventTouchUpInside];
}
return _publishButton;
}
- (NSMutableArray *)dataSource {
if (!_dataSource) {
_dataSource = [NSMutableArray array];
}
return _dataSource;
}
@end