// Created by AI on 2025-10-09. // Copyright © 2025 YuMi. All rights reserved. #import "EPMomentViewController.h" #import #import #import "EPMomentCell.h" #import "EPMomentListView.h" #import "EPMomentPublishViewController.h" #import "YUMIMacroUitls.h" @interface EPMomentViewController () // MARK: - UI Components @property (nonatomic, strong) EPMomentListView *listView; @property (nonatomic, strong) UIImageView *topIconImageView; @property (nonatomic, strong) UILabel *topTipLabel; @end @implementation EPMomentViewController // MARK: - Lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Enjoy your Life Time"; [self.navigationController.navigationBar setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor whiteColor] }]; [self setupUI]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMomentPublishSuccess:) name:EPMomentPublishSuccessNotification object:nil]; NSLog(@"[EPMomentViewController] 页面加载完成,UI 已设置"); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSLog(@"[EPMomentViewController] 首次 viewDidAppear,延迟 0.3s 后开始加载数据"); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSLog(@"[EPMomentViewController] 触发首次数据加载"); [self.listView reloadFirstPage]; }); }); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } // MARK: - Setup UI - (void)setupUI { 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.view addSubview:self.topIconImageView]; [self.topIconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view); make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(14); make.size.mas_equalTo(CGSizeMake(56, 41)); }]; [self.view addSubview:self.topTipLabel]; [self.topTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.topIconImageView.mas_bottom).offset(14); make.leading.trailing.equalTo(self.view).inset(20); }]; [self.view addSubview:self.listView]; [self.listView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.bottom.equalTo(self.view); make.top.equalTo(self.topTipLabel.mas_bottom).offset(8); }]; UIImage *addIcon = [UIImage imageNamed:@"icon_moment_add"]; UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom]; publishButton.contentMode = UIViewContentModeScaleAspectFit; [publishButton setImage:addIcon forState:UIControlStateNormal]; publishButton.frame = CGRectMake(0, 0, 40, 40); [publishButton addTarget:self action:@selector(onPublishButtonTapped) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *publishItem = [[UIBarButtonItem alloc] initWithCustomView:publishButton]; self.navigationItem.rightBarButtonItem = publishItem; NSLog(@"[EPMomentViewController] UI 设置完成"); } // MARK: - Actions - (void)onPublishButtonTapped { NSLog(@"[EPMomentViewController] 发布按钮点击"); EPMomentPublishViewController *vc = [[EPMomentPublishViewController alloc] init]; vc.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:vc animated:YES completion:nil]; } - (void)showAlertWithMessage:(NSString *)message { UIAlertController *alert = [UIAlertController alertControllerWithTitle:YMLocalizedString(@"common.tips") message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:YMLocalizedString(@"common.confirm") style:UIAlertActionStyleDefault handler:nil]]; [self presentViewController:alert animated:YES completion:nil]; } - (void)onMomentPublishSuccess:(NSNotification *)notification { NSLog(@"[EPMomentViewController] 收到发布成功通知,刷新列表"); [self.listView reloadFirstPage]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } // MARK: - Lazy Loading - (EPMomentListView *)listView { if (!_listView) { _listView = [[EPMomentListView alloc] initWithFrame:CGRectZero]; _listView.onSelectMoment = ^(NSInteger index) { }; } return _listView; } - (UIImageView *)topIconImageView { if (!_topIconImageView) { _topIconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_moment_Volume"]]; _topIconImageView.contentMode = UIViewContentModeScaleAspectFit; } return _topIconImageView; } - (UILabel *)topTipLabel { if (!_topTipLabel) { _topTipLabel = [UILabel new]; _topTipLabel.numberOfLines = 0; _topTipLabel.textColor = [UIColor whiteColor]; _topTipLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular]; _topTipLabel.text = @"In the quiet gallery of the heart, we learn to see the colors of emotion. And in the shared silence between souls, we begin to find the sound of resonance. This is more than an app—it's a space where your inner world is both a masterpiece and a melody."; } return _topTipLabel; } @end