Files
peko-ios/YuMi/Modules/YMNewHome/View/CreateEventViewControllerV2.m
2025-05-12 18:53:42 +08:00

794 lines
34 KiB
Objective-C

//
// CreateEventViewControllerV2.m
// YuMi
//
// Created by P on 2025/5/9.
//
#import "CreateEventViewControllerV2.h"
#import <Masonry/Masonry.h>
#import <PhotosUI/PhotosUI.h>
#import "CreateEventSelectRoomViewController.h"
#define MAX_EVENT_TITLE_LENGTH 20
#define MAX_EVENT_CONTENT_LENGTH 100
@interface CreateEventViewControllerV2 () <UITextViewDelegate, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHPickerViewControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) UIImage *selectedImage;
// 添加私有方法声明
- (UIButton *)createUploadBannerButtonWithTitle:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tag:(NSInteger)tag;
- (void)setupDatePicker; // 新增:设置日期选择器
- (void)showDatePicker; // 新增:显示日期选择器
- (void)hideDatePicker; // 新增:隐藏日期选择器
- (void)datePickerDoneTapped; // 新增:日期选择器确定按钮点击事件
- (void)datePickerCancelTapped; // 新增:日期选择器取消按钮点击事件
// 新增:时长选择器相关方法声明
- (void)setupDurationPicker;
- (void)showDurationPicker;
- (void)hideDurationPicker;
- (void)durationPickerDoneTapped;
- (void)durationPickerCancelTapped;
@end
@implementation CreateEventViewControllerV2
static const CGFloat kHorizontalPadding = 16.0;
static const CGFloat kVerticalPadding = 10.0;
static const CGFloat kSectionSpacing = 20.0;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"Create Event";
[self setupUI];
[self setupDatePicker]; // 新增:调用日期选择器设置方法
// [self setupDurationPicker]; // 新增:调用时长选择器设置方法
[self updateEventTitleCharCount];
[self updateEventContentCharCount];
self.selectedDurationInMinutes = 120; // Default to 2 hours
[self updateDurationLabel];
// 键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
// 点击空白收起键盘
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
// 设置 scrollView delegate
self.scrollView.delegate = self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary *userInfo = notification.userInfo;
CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
UIEdgeInsets insets = self.scrollView.contentInset;
insets.bottom = keyboardHeight + 20;
self.scrollView.contentInset = insets;
self.scrollView.scrollIndicatorInsets = insets;
}
- (void)keyboardWillHide:(NSNotification *)notification {
UIEdgeInsets insets = self.scrollView.contentInset;
insets.bottom = 0;
self.scrollView.contentInset = insets;
self.scrollView.scrollIndicatorInsets = insets;
}
- (void)dismissKeyboard {
[self.view endEditing:YES];
}
- (void)backButtonTapped {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)setupUI {
// ScrollView and ContentView
self.scrollView = [[UIScrollView alloc] init];
[self.view addSubview:self.scrollView];
self.contentView = [[UIView alloc] init];
[self.scrollView addSubview:self.contentView];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
// visualView.frame = CGRectMake(0, KScreenHeight - 46, KScreenWidth, 46);
[self.view addSubview:visualView];
// Create Event Button (fixed at bottom)
self.createEventButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.createEventButton setTitle:YMLocalizedString(@"20.20.59_text_8") forState:UIControlStateNormal];
[self.createEventButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // Adjust color as needed
[self.createEventButton addGradientBackgroundWithColors:@[
UIColorFromRGB(0xe29030),
UIColorFromRGB(0xfcc074),
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:23];
[self.createEventButton setCornerRadius:23];
self.createEventButton.userInteractionEnabled = NO;
self.createEventButton.alpha = 0.3;
[self.createEventButton addTarget:self action:@selector(createEventButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.createEventButton];
[self.createEventButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.view).offset(20);
make.trailing.equalTo(self.view).offset(-20);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);
make.height.mas_equalTo(46);
}];
[visualView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.view);
make.top.mas_equalTo(self.createEventButton.mas_top).offset(-20);
}];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
make.bottom.leading.trailing.equalTo(self.view);
// make.bottom.equalTo(self.createEventButton.mas_top).offset(-10); // Space above button
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self setupEventTitleSection];
[self setupEventBannerSection];
[self setupUploadBannerSection];
[self setupSelectRoomSection];
[self setupStartTimeSection];
[self setupDurationSection];
[self setupEventContentSection];
[self setupNotifyMyFansSection];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
#pragma mark - Helper Methods
- (UIButton *)createUploadBannerButtonWithTitle:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tag:(NSInteger)tag {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:kImage(imageName) forState:UIControlStateNormal];
[b setImage:kImage(selectedImageName) forState:UIControlStateSelected];
[b setTitle:title forState:UIControlStateNormal];
[b setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal];
[b.titleLabel setFont:kFontMedium(14)];
b.tag = tag;
return b;
}
- (UILabel *)createLabelWithText:(NSString *)text {
UILabel *label = [[UILabel alloc] init];
label.text = text;
label.font = kFontMedium(14);
label.textColor = UIColorFromRGB(0x313131);
return label;
}
- (UITextField *)createTextFieldWithPlaceholder:(NSString *)placeholder {
UITextField *textField = [[UITextField alloc] init];
textField.placeholder = placeholder;
textField.font = kFontRegular(14);
textField.textColor = UIColorFromRGB(0x313131);
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.layer.cornerRadius = 8;
textField.backgroundColor = UIColorFromRGB(0xf2f3f7);
return textField;
}
- (UILabel *)createCharCountLabel {
UILabel *label = [[UILabel alloc] init];
label.font = kFontRegular(12);
label.textColor = UIColorFromRGB(0x7b7b7d);
return label;
}
- (UIView *)createSelectionViewWithPlaceholder:(NSString *)placeholder target:(id)target action:(SEL)action {
UIView *view = [[UIView alloc] init];
view.backgroundColor = UIColorFromRGB(0xf2f3f7);
view.layer.cornerRadius = 8;
UILabel *label = [[UILabel alloc] init];
label.text = placeholder;
label.font = kFontRegular(14);
label.textColor = UIColorFromRGB(0x7b7b7d);
[view addSubview:label];
UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:kImage(@"event_arrow")];
[view addSubview:arrowImageView];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(view).offset(10);
make.centerY.equalTo(view);
}];
[arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.equalTo(view).offset(-10);
make.centerY.equalTo(view);
make.width.height.mas_equalTo(22);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[view addGestureRecognizer:tap];
view.userInteractionEnabled = YES;
if ([placeholder isEqualToString:YMLocalizedString(@"XPAnchorPKTableViewCell2")]) { // Store placeholder label for later update
if (action == @selector(selectRoomTapped)) self.selectRoomPlaceholderLabel = label;
else if (action == @selector(selectStartTimeTapped)) self.startTimePlaceholderLabel = label;
else if (action == @selector(selectDurationTapped)) self.durationPlaceholderLabel = label;
}
return view;
}
- (void)updateEventTitleCharCount {
NSInteger currentLength = self.eventTitleTextField.text.length;
self.eventTitleCharCountLabel.text = [NSString stringWithFormat:@"%ld/%d", (long)currentLength, MAX_EVENT_TITLE_LENGTH];
}
- (void)updateEventContentCharCount {
NSInteger currentLength = self.eventContentTextView.text.length;
self.eventContentCharCountLabel.text = [NSString stringWithFormat:@"%ld/%d", (long)currentLength, MAX_EVENT_CONTENT_LENGTH];
}
#pragma mark - Actions
- (void)eventBannerTapped {
NSLog(@"Event Banner Tapped");
if (@available(iOS 14, *)) {
PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
config.filter = [PHPickerFilter imagesFilter];
config.selectionLimit = 1;
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:config];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
} else {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
}
- (void)selectRoomTapped {
NSLog(@"Select Room Tapped");
CreateEventSelectRoomViewController *vc = [[CreateEventSelectRoomViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
// Placeholder: Show a room selection UI (e.g., UIPickerView or new VC)
// For now, just update the label
// self.selectRoomPlaceholderLabel.text = @"Room A";
// self.selectRoomPlaceholderLabel.textColor = [UIColor blackColor];
// [self checkCreateEventButtonState];
}
- (void)selectStartTimeTapped {
NSLog(@"Select Start Time Tapped");
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
self.startTimePlaceholderLabel.text = [formatter stringFromDate:[NSDate date]];
self.startTimePlaceholderLabel.textColor = [UIColor blackColor];
[self checkCreateEventButtonState];
}
- (void)selectDurationTapped {
NSLog(@"Select Duration Tapped");
// Placeholder: Show a duration picker
// self.durationPlaceholderLabel.text = @"2 hours";
// self.durationPlaceholderLabel.textColor = [UIColor blackColor];
self.datePickerContainerView.hidden = NO;
[self checkCreateEventButtonState];
}
- (void)createEventButtonTapped {
NSLog(@"Create Event Tapped");
// Gather all data and proceed with event creation logic
NSString *title = self.eventTitleTextField.text;
UIImage *bannerImage = self.eventBannerImageView.image;
BOOL uploadToHomepage = self.uploadBannerYesButton.selected;
NSString *selectedRoom = self.selectRoomPlaceholderLabel.text; // This is a placeholder, get actual ID
NSString *startTime = self.startTimePlaceholderLabel.text; // This is a placeholder, get actual NSDate
NSString *duration = self.durationPlaceholderLabel.text; // This is a placeholder, get actual duration value
NSString *content = self.eventContentTextView.text;
BOOL notifyFans = self.notifyFansSwitch.isOn;
// Basic Validation (can be expanded)
if (title.length == 0) {
NSLog(@"Event title is missing");
return;
}
if (!bannerImage) {
NSLog(@"Event banner is missing");
// return; // Allow creating event without banner for now, or enforce
}
// ... more validations
NSLog(@"Title: %@, Upload: %d, Room: %@, Start: %@, Duration: %@, Content: %@, Notify: %d",
title, uploadToHomepage, selectedRoom, startTime, duration, content, notifyFans);
// TODO: Call presenter or service to create event
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.eventTitleTextField) {
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (newString.length > MAX_EVENT_TITLE_LENGTH) {
return NO;
}
}
return YES;
}
- (void)textFieldDidChangeSelection:(UITextField *)textField {
if (textField == self.eventTitleTextField) {
[self updateEventTitleCharCount];
[self checkCreateEventButtonState];
}
}
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
if (textView == self.eventContentTextView) {
[self updateEventContentCharCount];
[self checkCreateEventButtonState];
// Optional: Add placeholder behavior for UITextView if needed
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (textView == self.eventContentTextView) {
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
if (newText.length > MAX_EVENT_CONTENT_LENGTH) {
return NO;
}
}
return YES;
}
- (void)uploadBannerButtonTapped:(UIButton *)sender {
if (sender == self.uploadBannerYesButton) {
if (!self.uploadBannerYesButton.selected) { // 避免重复设置
self.uploadBannerYesButton.selected = YES;
self.uploadBannerNoButton.selected = NO;
// 可在此处处理横幅上传状态的逻辑,例如: self.shouldUploadBanner = YES;
}
} else if (sender == self.uploadBannerNoButton) {
if (!self.uploadBannerNoButton.selected) { // 避免重复设置
self.uploadBannerYesButton.selected = NO;
self.uploadBannerNoButton.selected = YES;
// 可在此处处理横幅上传状态的逻辑,例如: self.shouldUploadBanner = NO;
}
}
[self checkCreateEventButtonState];
}
#pragma mark - UIImagePickerControllerDelegate (Legacy)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
UIImage *selectedImage = info[UIImagePickerControllerOriginalImage];
if (selectedImage) {
self.selectedImage = selectedImage;
self.eventBannerImageView.image = selectedImage;
self.eventBannerCamearImageView.hidden = NO; // Hide placeholder once image is selected
}
[picker dismissViewControllerAnimated:YES completion:nil];
[self checkCreateEventButtonState];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - PHPickerViewControllerDelegate (iOS 14+)
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results API_AVAILABLE(ios(14)) {
[picker dismissViewControllerAnimated:YES completion:nil];
if (results.count == 0) {
[self checkCreateEventButtonState];
return;
}
PHPickerResult *result = results.firstObject;
if ([result.itemProvider canLoadObjectOfClass:[UIImage class]]) {
[result.itemProvider loadObjectOfClass:[UIImage class] completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error) {
if ([object isKindOfClass:[UIImage class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
self.selectedImage = (UIImage *)object;
self.eventBannerImageView.image = (UIImage *)object;
self.eventBannerCamearImageView.hidden = NO; // Hide placeholder
[self checkCreateEventButtonState];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self checkCreateEventButtonState];
});
}
}];
} else {
[self checkCreateEventButtonState];
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Date Picker Methods
- (void)setupDatePicker {
// Container View
self.datePickerContainerView = [[UIView alloc] init];
self.datePickerContainerView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; // Semi-transparent background
[self.view addSubview:self.datePickerContainerView];
self.datePickerContainerView.hidden = YES; // Initially hidden
[self.datePickerContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// Picker Toolbar
self.pickerToolbar = [[UIToolbar alloc] init];
self.pickerToolbar.barStyle = UIBarStyleDefault;
[self.pickerToolbar sizeToFit];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(datePickerCancelTapped)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(datePickerDoneTapped)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.pickerToolbar setItems:@[cancelButton, flexibleSpace, doneButton]];
[self.datePickerContainerView addSubview:self.pickerToolbar];
// Date Picker
self.datePicker = [[UIDatePicker alloc] init];
self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
if (@available(iOS 13.4, *)) {
self.datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
}
self.datePicker.backgroundColor = [UIColor whiteColor];
[self.datePickerContainerView addSubview:self.datePicker];
self.pickerToolbar.translatesAutoresizingMaskIntoConstraints = NO;
self.datePicker.translatesAutoresizingMaskIntoConstraints = NO;
// Constraints for Toolbar and DatePicker
[self.pickerToolbar mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self.datePickerContainerView);
make.bottom.equalTo(self.datePicker.mas_top);
make.height.mas_equalTo(44);
}];
[self.datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.datePickerContainerView);
make.height.mas_equalTo(216);
}];
}
- (void)showDatePicker {
[self.view bringSubviewToFront:self.datePickerContainerView];
self.datePickerContainerView.hidden = NO;
self.datePickerContainerView.alpha = 0;
[UIView animateWithDuration:0.3 animations:^{
self.datePickerContainerView.alpha = 1;
}];
}
- (void)hideDatePicker {
[UIView animateWithDuration:0.3 animations:^{
self.datePickerContainerView.alpha = 0;
} completion:^(BOOL finished) {
self.datePickerContainerView.hidden = YES;
}];
}
- (void)datePickerDoneTapped {
self.selectedStartTime = self.datePicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; // Customize format as needed
NSString *formattedDate = [dateFormatter stringFromDate:self.selectedStartTime];
self.startTimePlaceholderLabel.text = formattedDate;
// If you have a placeholder color, change it back to normal text color
// self.startTimePlaceholderLabel.textColor = [UIColor blackColor];
[self hideDatePicker];
}
- (void)datePickerCancelTapped {
[self hideDatePicker];
}
- (void)updateDurationLabel {
NSInteger hours = self.selectedDurationInMinutes / 60;
NSInteger minutes = self.selectedDurationInMinutes % 60;
NSString *durationString;
if (hours > 0 && minutes > 0) {
durationString = [NSString stringWithFormat:@"%ldh %ldm", (long)hours, (long)minutes];
} else if (hours > 0) {
durationString = [NSString stringWithFormat:@"%ldh", (long)hours];
} else if (minutes > 0) {
durationString = [NSString stringWithFormat:@"%ldm", (long)minutes];
} else {
durationString = @"Select"; // Or some default placeholder
}
UILabel *label = (UILabel *)[self.durationView viewWithTag:100];
if (label) {
label.text = durationString;
}
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
if (pickerView == self.durationPicker) {
return 2; // Hours and Minutes
}
return 0;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (pickerView == self.durationPicker) {
if (component == 0) { // Hours component
return 24; // 1 to 24 hours
} else if (component == 1) { // Minutes component
return 12; // 0, 5, 10, ..., 55 minutes (12 options)
}
}
return 0;
}
#pragma mark - UIPickerViewDelegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (pickerView == self.durationPicker) {
if (component == 0) { // Hours component
return [NSString stringWithFormat:@"%ld h", (long)row + 1];
} else if (component == 1) { // Minutes component
return [NSString stringWithFormat:@"%02ld m", (long)row * 5];
}
}
return nil;
}
#pragma mark - Event Title Section
- (void)setupEventTitleSection {
self.eventTitleLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_9")];
[self.contentView addSubview:self.eventTitleLabel];
self.eventTitleTextField = [self createTextFieldWithPlaceholder:@""];
self.eventTitleTextField.delegate = self;
[self.contentView addSubview:self.eventTitleTextField];
self.eventTitleCharCountLabel = [self createCharCountLabel];
[self.contentView addSubview:self.eventTitleCharCountLabel];
[self.eventTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventTitleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventTitleLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
[self.eventTitleCharCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY
.equalTo(self.eventTitleLabel);
make.trailing.equalTo(self.eventTitleTextField);
}];
}
#pragma mark - Event Banner Section
- (void)setupEventBannerSection {
self.eventBannerLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_10")];
[self.contentView addSubview:self.eventBannerLabel];
self.eventBannerImageView = [[UIImageView alloc] initWithImage:kImage(@"event_take_photo")];
self.eventBannerImageView.contentMode = UIViewContentModeScaleAspectFill;
self.eventBannerImageView.clipsToBounds = YES;
self.eventBannerImageView.layer.cornerRadius = 8;
self.eventBannerImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *bannerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(eventBannerTapped)];
[self.eventBannerImageView addGestureRecognizer:bannerTap];
[self.contentView addSubview:self.eventBannerImageView];
self.eventBannerCamearImageView = [[UIImageView alloc] initWithImage:kImage(@"event_camear")];
self.eventBannerCamearImageView.hidden = YES;
[self.eventBannerImageView addSubview:self.eventBannerCamearImageView];
[self.eventBannerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventTitleTextField.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventBannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(118); // Adjust height as needed
}];
[self.eventBannerCamearImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.trailing.equalTo(self.eventBannerImageView);
make.width.height.mas_equalTo(32);
}];
}
#pragma mark - Upload Banner Section
- (void)setupUploadBannerSection {
self.uploadBannerLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_11")];
[self.contentView addSubview:self.uploadBannerLabel];
self.uploadBannerYesButton = [self createUploadBannerButtonWithTitle:YMLocalizedString(@"20.20.59_text_12") imageName:@"event_non_select" selectedImageName:@"event_selected" tag:0];
self.uploadBannerYesButton.selected = YES;
[self.uploadBannerYesButton addTarget:self action:@selector(uploadBannerButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.uploadBannerYesButton];
self.uploadBannerNoButton = [self createUploadBannerButtonWithTitle:YMLocalizedString(@"20.20.59_text_13") imageName:@"event_non_select" selectedImageName:@"event_selected" tag:1];
self.uploadBannerNoButton.selected = NO;
[self.uploadBannerNoButton addTarget:self action:@selector(uploadBannerButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.uploadBannerNoButton];
[self.uploadBannerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventBannerImageView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.uploadBannerYesButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
make.height.mas_equalTo(20);
}];
[self.uploadBannerNoButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.equalTo(self.uploadBannerYesButton.mas_trailing).offset(70);
make.trailing.lessThanOrEqualTo(self.contentView).offset(-16);
make.height.height.equalTo(self.uploadBannerYesButton);
}];
}
#pragma mark - Select Room Section
- (void)setupSelectRoomSection {
self.selectRoomLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_14")];
[self.contentView addSubview:self.selectRoomLabel];
self.selectRoomView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2") target:self action:@selector(selectRoomTapped)];
[self.contentView addSubview:self.selectRoomView];
[self.selectRoomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerYesButton.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.selectRoomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.selectRoomLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(44);
}];
}
#pragma mark - Start Time Section
- (void)setupStartTimeSection {
self.startTimeLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_15")];
[self.contentView addSubview:self.startTimeLabel];
self.startTimeView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2")
target:self
action:@selector(selectStartTimeTapped)];
[self.contentView addSubview:self.startTimeView];
[self.startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.selectRoomView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.startTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.startTimeLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Duration Section
- (void)setupDurationSection {
self.durationLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_16")];
[self.contentView addSubview:self.durationLabel];
self.durationView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2") target:self action:@selector(selectDurationTapped)];
[self.contentView addSubview:self.durationView];
[self.durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.startTimeView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.durationView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.durationLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Event Content Section
- (void)setupEventContentSection {
self.eventContentLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_17")];
[self.contentView addSubview:self.eventContentLabel];
self.eventContentTextView = [[UITextView alloc] init];
self.eventContentTextView.backgroundColor = UIColorFromRGB(0xf2f3f7);
self.eventContentTextView.font = kFontRegular(14);
self.eventContentTextView.textColor = UIColorFromRGB(0x313131);
self.eventContentTextView.layer.cornerRadius = 8;
self.eventContentTextView.delegate = self;
[self.contentView addSubview:self.eventContentTextView];
self.eventContentCharCountLabel = [self createCharCountLabel];
[self.contentView addSubview:self.eventContentCharCountLabel];
[self.eventContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.durationView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventContentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventContentLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(152);
}];
[self.eventContentCharCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.eventContentLabel);
make.trailing.equalTo(self.eventContentTextView.mas_trailing);
}];
}
#pragma mark - Notify My Fans Section
- (void)setupNotifyMyFansSection {
self.notifyFansLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_18")];
[self.contentView addSubview:self.notifyFansLabel];
self.notifyFansSwitch = [[UISwitch alloc] init];
[self.contentView addSubview:self.notifyFansSwitch];
[self.notifyFansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventContentTextView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.notifyFansSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.notifyFansLabel);
make.trailing.equalTo(self.contentView).offset(-kHorizontalPadding);
make.bottom.equalTo(self.contentView).offset(-kSectionSpacing);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.greaterThanOrEqualTo(self.notifyFansSwitch.mas_bottom).offset(20 + 60);
}];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self dismissKeyboard];
}
- (void)checkCreateEventButtonState {
NSString *placeholder = YMLocalizedString(@"XPAnchorPKTableViewCell2");
BOOL hasTitle = self.eventTitleTextField.text.length > 0;
BOOL hasBanner = self.selectedImage != nil;
BOOL hasRoom = self.selectRoomPlaceholderLabel.text.length > 0 && ![self.selectRoomPlaceholderLabel.text isEqualToString:placeholder];
BOOL hasStartTime = self.startTimePlaceholderLabel.text.length > 0 && ![self.startTimePlaceholderLabel.text isEqualToString:placeholder];
BOOL hasDuration = self.durationPlaceholderLabel.text.length > 0 && ![self.durationPlaceholderLabel.text isEqualToString:placeholder];
BOOL hasContent = self.eventContentTextView.text.length > 0;
if (hasTitle && hasBanner && hasRoom && hasStartTime && hasDuration && hasContent) {
self.createEventButton.alpha = 1.0;
self.createEventButton.userInteractionEnabled = YES;
} else {
self.createEventButton.alpha = 0.3;
self.createEventButton.userInteractionEnabled = NO;
}
}
@end