From 6556689c8f5766b406bee9c44999ee4cb8d1eefd Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 3 Dec 2025 15:46:26 +0800 Subject: [PATCH] 1 --- keyBoard/Class/Login/VC/KBEmailLoginVC.h | 4 +- keyBoard/Class/Login/VC/KBEmailLoginVC.m | 518 +++++++++++++++++++++- keyBoard/Class/Login/VC/KBEmailRegistVC.m | 165 ++++--- 3 files changed, 612 insertions(+), 75 deletions(-) diff --git a/keyBoard/Class/Login/VC/KBEmailLoginVC.h b/keyBoard/Class/Login/VC/KBEmailLoginVC.h index 5dd5a25..1516fff 100644 --- a/keyBoard/Class/Login/VC/KBEmailLoginVC.h +++ b/keyBoard/Class/Login/VC/KBEmailLoginVC.h @@ -5,11 +5,11 @@ // Created by Mac on 2025/12/3. // -#import +#import "BaseViewController.h" NS_ASSUME_NONNULL_BEGIN -@interface KBEmailLoginVC : UIViewController +@interface KBEmailLoginVC : BaseViewController @end diff --git a/keyBoard/Class/Login/VC/KBEmailLoginVC.m b/keyBoard/Class/Login/VC/KBEmailLoginVC.m index ed41d7e..9dc75f4 100644 --- a/keyBoard/Class/Login/VC/KBEmailLoginVC.m +++ b/keyBoard/Class/Login/VC/KBEmailLoginVC.m @@ -7,7 +7,39 @@ #import "KBEmailLoginVC.h" -@interface KBEmailLoginVC () +@interface KBEmailLoginVC () + +// 背景与顶部装饰 +@property (nonatomic, strong) UIImageView *bgImageView; // 整体背景图:login_bg_icon +@property (nonatomic, strong) UIImageView *topRightImageView; // 顶部右侧装饰图:login_jianp_icon +@property (nonatomic, strong) UIButton *backButton; // 顶部左侧返回按钮 + +// 底部白色容器(仅上圆角 26) +@property (nonatomic, strong) UIView *contentContainerView; + +// 可滚动区域(小屏内容多时允许纵向滚动) +@property (nonatomic, strong) UIScrollView *scrollView; +@property (nonatomic, strong) UIView *scrollContentView; + +// 标题 +@property (nonatomic, strong) UILabel *titleLabel; + +// 输入框 +@property (nonatomic, strong) UIView *emailFieldContainer; +@property (nonatomic, strong) UITextField *emailTextField; + +@property (nonatomic, strong) UIView *passwordFieldContainer; +@property (nonatomic, strong) UITextField *passwordTextField; +@property (nonatomic, strong) UIButton *passwordToggleButton; // 显示/隐藏密码 + +// 操作按钮 +@property (nonatomic, strong) UIButton *forgotPasswordButton; +@property (nonatomic, strong) UIButton *submitButton; // Login + +// 协议 & 底部文案 +@property (nonatomic, strong) UITextView *agreementTextView; +@property (nonatomic, strong) UILabel *accountTipLabel; // “Don't Have An Account?” +@property (nonatomic, strong) UIButton *signUpButton; // “Sign Up” @end @@ -15,17 +47,483 @@ - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. + // 与登录/注册页一致:隐藏通用导航栏,使用自定义背景 + 返回按钮 + self.kb_enableCustomNavBar = NO; + self.view.backgroundColor = [UIColor whiteColor]; + + [self setupUI]; } -/* -#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. +- (void)viewDidLayoutSubviews { + [super viewDidLayoutSubviews]; + // 仅白色容器顶部圆角 + if (!CGRectIsEmpty(self.contentContainerView.bounds)) { + UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight; + UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.contentContainerView.bounds + byRoundingCorners:corners + cornerRadii:CGSizeMake(26, 26)]; + CAShapeLayer *mask = [CAShapeLayer layer]; + mask.frame = self.contentContainerView.bounds; + mask.path = path.CGPath; + self.contentContainerView.layer.mask = mask; + } +} + +#pragma mark - UI + +- (void)setupUI { + // 背景图 + [self.view addSubview:self.bgImageView]; + [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.view); + }]; + + // 顶部左侧返回按钮 + [self.view addSubview:self.backButton]; + [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.view).offset(16); + make.top.equalTo(self.view).offset(KB_StatusBarHeight() + 8); + make.width.height.mas_equalTo(32); + }]; + + // 顶部右侧装饰图 + [self.view addSubview:self.topRightImageView]; + [self.topRightImageView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.view).offset(KB_StatusBarHeight() + KBFit(24)); + make.right.equalTo(self.view).offset(KBFit(10)); + make.width.mas_equalTo(KBFit(244)); + make.height.mas_equalTo(KBFit(224)); + }]; + + // 底部白色容器 + [self.view addSubview:self.contentContainerView]; + [self.contentContainerView mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.bottom.equalTo(self.view); + make.top.equalTo(self.view).offset(KBFit(272)); + }]; + + // Scroll 区域 + [self.contentContainerView addSubview:self.scrollView]; + [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.contentContainerView); + }]; + + [self.scrollView addSubview:self.scrollContentView]; + [self.scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.scrollView); + make.width.equalTo(self.scrollView); + }]; + + // 标题:Login With Email Password + [self.scrollContentView addSubview:self.titleLabel]; + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.scrollContentView).offset(27); + make.centerX.equalTo(self.scrollContentView); + }]; + + // 邮箱输入 + [self.scrollContentView addSubview:self.emailFieldContainer]; + [self.emailFieldContainer mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.titleLabel.mas_bottom).offset(24); + make.left.equalTo(self.scrollContentView).offset(30); + make.right.equalTo(self.scrollContentView).offset(-30); + make.height.mas_equalTo(52); + }]; + + [self.emailFieldContainer addSubview:self.emailTextField]; + [self.emailTextField mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.emailFieldContainer).insets(UIEdgeInsetsMake(0, 16, 0, 16)); + }]; + + // 密码输入 + [self.scrollContentView addSubview:self.passwordFieldContainer]; + [self.passwordFieldContainer mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.emailFieldContainer.mas_bottom).offset(16); + make.left.right.equalTo(self.emailFieldContainer); + make.height.equalTo(self.emailFieldContainer); + }]; + + [self.passwordFieldContainer addSubview:self.passwordToggleButton]; + [self.passwordToggleButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerY.equalTo(self.passwordFieldContainer); + make.right.equalTo(self.passwordFieldContainer).offset(-16); + make.width.height.mas_equalTo(24); + }]; + + [self.passwordFieldContainer addSubview:self.passwordTextField]; + [self.passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.bottom.equalTo(self.passwordFieldContainer); + make.left.equalTo(self.passwordFieldContainer).offset(16); + make.right.equalTo(self.passwordToggleButton.mas_left).offset(-8); + }]; + + // Forgot Password? + [self.scrollContentView addSubview:self.forgotPasswordButton]; + [self.forgotPasswordButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.passwordFieldContainer.mas_bottom).offset(12); + make.right.equalTo(self.passwordFieldContainer); + }]; + + // Login 按钮 + [self.scrollContentView addSubview:self.submitButton]; + [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.forgotPasswordButton.mas_bottom).offset(24); + make.left.right.equalTo(self.emailFieldContainer); + make.height.mas_equalTo(56); + }]; + + // 协议文案 + [self.scrollContentView addSubview:self.agreementTextView]; + [self.agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.submitButton.mas_bottom).offset(24); + make.left.equalTo(self.scrollContentView).offset(30); + make.right.equalTo(self.scrollContentView).offset(-30); + }]; + + // 底部账号切换文案 + UIView *accountLine = [UIView new]; + [self.scrollContentView addSubview:accountLine]; + [accountLine mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self.agreementTextView.mas_bottom).offset(12); + make.centerX.equalTo(self.scrollContentView); + make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16); + }]; + + [accountLine addSubview:self.accountTipLabel]; + [accountLine addSubview:self.signUpButton]; + + [self.accountTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.left.bottom.equalTo(accountLine); + }]; + + [self.signUpButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.accountTipLabel.mas_right).offset(4); + make.right.equalTo(accountLine); + make.centerY.equalTo(self.accountTipLabel); + }]; +} + +#pragma mark - Actions + +- (void)onTapBack { + if (self.navigationController && self.navigationController.viewControllers.count > 1) { + [self.navigationController popViewControllerAnimated:YES]; + } else if (self.presentingViewController) { + [self dismissViewControllerAnimated:YES completion:nil]; + } +} + +- (void)onTapSubmit { + KBLOG(@"KBEmailLoginVC onTapSubmit, email=%@, pwdLen=%zd", + self.emailTextField.text, + self.passwordTextField.text.length); +} + +- (void)onTapForgotPassword { + KBLOG(@"KBEmailLoginVC onTapForgotPassword"); +} + +- (void)onTapSignUp { + KBLOG(@"KBEmailLoginVC onTapSignUp"); +} + +- (void)onTapTogglePassword:(UIButton *)sender { + sender.selected = !sender.selected; + self.passwordTextField.secureTextEntry = !sender.selected; +} + +- (void)kb_handleAgreementTap:(UITapGestureRecognizer *)tap { + UITextView *textView = self.agreementTextView; + CGPoint point = [tap locationInView:textView]; + + CGPoint location = point; + location.x -= textView.textContainerInset.left; + location.y -= textView.textContainerInset.top; + + NSLayoutManager *layoutManager = textView.layoutManager; + NSTextContainer *textContainer = textView.textContainer; + NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:location + inTextContainer:textContainer]; + if (glyphIndex >= textView.textStorage.length) { return; } + + NSUInteger charIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; + + NSString *lowerFull = textView.text.lowercaseString ?: @""; + NSRange termsRange = [lowerFull rangeOfString:@"terms of service"]; + NSRange privacyRange = [lowerFull rangeOfString:@"privacy policy"]; + + BOOL hitTerms = (termsRange.location != NSNotFound && NSLocationInRange(charIndex, termsRange)); + BOOL hitPrivacy = (privacyRange.location != NSNotFound && NSLocationInRange(charIndex, privacyRange)); + if (hitTerms || hitPrivacy) { + KBLOG(@"KBEmailLoginVC tap policy"); + } +} + +#pragma mark - UITextFieldDelegate + +- (BOOL)textFieldShouldReturn:(UITextField *)textField { + if (textField == self.emailTextField) { + [self.passwordTextField becomeFirstResponder]; + } else if (textField == self.passwordTextField) { + [textField resignFirstResponder]; + [self onTapSubmit]; + } + return YES; +} + +#pragma mark - Lazy UI + +- (UIImageView *)bgImageView { + if (!_bgImageView) { + _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_bg_icon"]]; + _bgImageView.contentMode = UIViewContentModeScaleAspectFill; + _bgImageView.clipsToBounds = YES; + } + return _bgImageView; +} + +- (UIImageView *)topRightImageView { + if (!_topRightImageView) { + _topRightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_jianp_icon"]]; + _topRightImageView.contentMode = UIViewContentModeScaleAspectFit; + _topRightImageView.clipsToBounds = YES; + } + return _topRightImageView; +} + +- (UIButton *)backButton { + if (!_backButton) { + _backButton = [UIButton buttonWithType:UIButtonTypeCustom]; + UIImage *img = [UIImage imageNamed:@"back"]; + if (!img) { img = [UIImage imageNamed:@"back_black_icon"]; } + if (img) { + [_backButton setImage:img forState:UIControlStateNormal]; + } + _backButton.adjustsImageWhenHighlighted = YES; + _backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + [_backButton addTarget:self action:@selector(onTapBack) forControlEvents:UIControlEventTouchUpInside]; + } + return _backButton; +} + +- (UIView *)contentContainerView { + if (!_contentContainerView) { + _contentContainerView = [UIView new]; + _contentContainerView.backgroundColor = [UIColor whiteColor]; + } + return _contentContainerView; +} + +- (UIScrollView *)scrollView { + if (!_scrollView) { + _scrollView = [UIScrollView new]; + _scrollView.showsVerticalScrollIndicator = NO; + _scrollView.alwaysBounceVertical = NO; + _scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; + } + return _scrollView; +} + +- (UIView *)scrollContentView { + if (!_scrollContentView) { + _scrollContentView = [UIView new]; + _scrollContentView.backgroundColor = [UIColor clearColor]; + } + return _scrollContentView; +} + +- (UILabel *)titleLabel { + if (!_titleLabel) { + _titleLabel = [UILabel new]; + _titleLabel.text = KBLocalized(@"Login With Email Password"); + _titleLabel.textColor = [UIColor colorWithHex:KBBlackValue]; + _titleLabel.font = [KBFont bold:18]; + _titleLabel.textAlignment = NSTextAlignmentCenter; + } + return _titleLabel; +} + +- (UIView *)emailFieldContainer { + if (!_emailFieldContainer) { + _emailFieldContainer = [UIView new]; + _emailFieldContainer.backgroundColor = [UIColor colorWithHex:0xF7F7F7]; + _emailFieldContainer.layer.cornerRadius = 10.0; + _emailFieldContainer.layer.masksToBounds = YES; + } + return _emailFieldContainer; +} + +- (UITextField *)emailTextField { + if (!_emailTextField) { + _emailTextField = [[UITextField alloc] init]; + _emailTextField.delegate = self; + _emailTextField.keyboardType = UIKeyboardTypeEmailAddress; + _emailTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; + _emailTextField.autocorrectionType = UITextAutocorrectionTypeNo; + _emailTextField.clearButtonMode = UITextFieldViewModeWhileEditing; + _emailTextField.textColor = [UIColor colorWithHex:KBBlackValue]; + _emailTextField.font = [KBFont regular:14]; + _emailTextField.returnKeyType = UIReturnKeyNext; + + NSString *ph = KBLocalized(@"Please Enter Your Email Address"); + _emailTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:ph + attributes:@{ + NSForegroundColorAttributeName : [UIColor colorWithWhite:0.75 alpha:1.0], + NSFontAttributeName : [KBFont regular:14] + }]; + } + return _emailTextField; +} + +- (UIView *)passwordFieldContainer { + if (!_passwordFieldContainer) { + _passwordFieldContainer = [UIView new]; + _passwordFieldContainer.backgroundColor = [UIColor colorWithHex:0xF7F7F7]; + _passwordFieldContainer.layer.cornerRadius = 10.0; + _passwordFieldContainer.layer.masksToBounds = YES; + } + return _passwordFieldContainer; +} + +- (UITextField *)passwordTextField { + if (!_passwordTextField) { + _passwordTextField = [[UITextField alloc] init]; + _passwordTextField.delegate = self; + _passwordTextField.secureTextEntry = YES; + _passwordTextField.textColor = [UIColor colorWithHex:KBBlackValue]; + _passwordTextField.font = [KBFont regular:14]; + _passwordTextField.returnKeyType = UIReturnKeyDone; + + NSString *ph = KBLocalized(@"Please Enter The Password"); + _passwordTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:ph + attributes:@{ + NSForegroundColorAttributeName : [UIColor colorWithWhite:0.75 alpha:1.0], + NSFontAttributeName : [KBFont regular:14] + }]; + } + return _passwordTextField; +} + +- (UIButton *)passwordToggleButton { + if (!_passwordToggleButton) { + _passwordToggleButton = [UIButton buttonWithType:UIButtonTypeCustom]; + UIImage *eye = [UIImage imageNamed:@"login_eye_icon"]; + UIImage *eyeSlash = [UIImage imageNamed:@"login_eyeslash_icon"]; + [_passwordToggleButton setImage:eye forState:UIControlStateNormal]; + [_passwordToggleButton setImage:eyeSlash forState:UIControlStateSelected]; + [_passwordToggleButton addTarget:self + action:@selector(onTapTogglePassword:) + forControlEvents:UIControlEventTouchUpInside]; + } + return _passwordToggleButton; +} + +- (UIButton *)forgotPasswordButton { + if (!_forgotPasswordButton) { + _forgotPasswordButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_forgotPasswordButton setTitle:KBLocalized(@"Forgot Password?") forState:UIControlStateNormal]; + [_forgotPasswordButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; + _forgotPasswordButton.titleLabel.font = [KBFont regular:10]; + [_forgotPasswordButton addTarget:self + action:@selector(onTapForgotPassword) + forControlEvents:UIControlEventTouchUpInside]; + } + return _forgotPasswordButton; +} + +- (UIButton *)submitButton { + if (!_submitButton) { + _submitButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_submitButton setTitle:KBLocalized(@"Login") forState:UIControlStateNormal]; + [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + _submitButton.titleLabel.font = [KBFont medium:16]; + _submitButton.backgroundColor = [UIColor colorWithHex:KBColorValue]; + _submitButton.layer.cornerRadius = 28.0; + _submitButton.layer.masksToBounds = YES; + [_submitButton addTarget:self + action:@selector(onTapSubmit) + forControlEvents:UIControlEventTouchUpInside]; + } + return _submitButton; +} + +- (UITextView *)agreementTextView { + if (!_agreementTextView) { + _agreementTextView = [UITextView new]; + _agreementTextView.backgroundColor = [UIColor clearColor]; + _agreementTextView.editable = NO; + _agreementTextView.selectable = NO; + _agreementTextView.scrollEnabled = NO; + _agreementTextView.textAlignment = NSTextAlignmentCenter; + _agreementTextView.textContainerInset = UIEdgeInsetsZero; + _agreementTextView.textContainer.lineFragmentPadding = 0; + + NSString *fullText = @"By continuing, you agree to our terms of service and confirm that you have read our privacy policy"; + NSString *termsText = @"terms of service"; + NSString *privacyText = @"privacy policy"; + + NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init]; + paragraph.alignment = NSTextAlignmentCenter; + + NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:fullText + attributes:@{ + NSFontAttributeName : [KBFont regular:10], + NSForegroundColorAttributeName : [UIColor colorWithHex:0x717171], + NSParagraphStyleAttributeName : paragraph + }]; + + NSString *lowerFull = fullText.lowercaseString; + NSRange termsRange = [lowerFull rangeOfString:termsText.lowercaseString]; + if (termsRange.location != NSNotFound) { + [attr addAttributes:@{ + NSForegroundColorAttributeName : [UIColor colorWithHex:KBBlackValue], + NSUnderlineStyleAttributeName : @(NSUnderlineStyleNone) + } range:termsRange]; + } + + NSRange privacyRange = [lowerFull rangeOfString:privacyText.lowercaseString]; + if (privacyRange.location != NSNotFound) { + [attr addAttributes:@{ + NSForegroundColorAttributeName : [UIColor colorWithHex:KBBlackValue], + NSUnderlineStyleAttributeName : @(NSUnderlineStyleNone) + } range:privacyRange]; + } + + _agreementTextView.linkTextAttributes = @{ + NSForegroundColorAttributeName : [UIColor colorWithHex:KBBlackValue], + NSUnderlineStyleAttributeName : @(NSUnderlineStyleNone) + }; + _agreementTextView.attributedText = attr; + + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(kb_handleAgreementTap:)]; + _agreementTextView.userInteractionEnabled = YES; + [_agreementTextView addGestureRecognizer:tap]; + } + return _agreementTextView; +} + +- (UILabel *)accountTipLabel { + if (!_accountTipLabel) { + _accountTipLabel = [UILabel new]; + _accountTipLabel.text = KBLocalized(@"Don't Have An Account?"); + _accountTipLabel.font = [KBFont regular:10]; + _accountTipLabel.textColor = [UIColor colorWithHex:KBBlackValue]; + } + return _accountTipLabel; +} + +- (UIButton *)signUpButton { + if (!_signUpButton) { + _signUpButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_signUpButton setTitle:KBLocalized(@"Sign Up") forState:UIControlStateNormal]; + [_signUpButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; + _signUpButton.titleLabel.font = [KBFont medium:10]; + [_signUpButton addTarget:self + action:@selector(onTapSignUp) + forControlEvents:UIControlEventTouchUpInside]; + } + return _signUpButton; } -*/ @end diff --git a/keyBoard/Class/Login/VC/KBEmailRegistVC.m b/keyBoard/Class/Login/VC/KBEmailRegistVC.m index a05ba32..cc224d3 100644 --- a/keyBoard/Class/Login/VC/KBEmailRegistVC.m +++ b/keyBoard/Class/Login/VC/KBEmailRegistVC.m @@ -6,6 +6,10 @@ // #import "KBEmailRegistVC.h" +#import "KBEmailLoginVC.h" +#import +#import "KBLoginVM.h" +#import "AppDelegate.h" @interface KBEmailRegistVC () @@ -40,13 +44,13 @@ @property (nonatomic, strong) UIButton *submitButton; // 绿色 Login 按钮 // 其他登录方式 -@property (nonatomic, strong) UIButton *appleLoginButton; // Continue Through Apple +@property (nonatomic, strong) UIControl *appleLoginButton; // Continue Through Apple(ASAuthorizationAppleIDButton) @property (nonatomic, strong) UIButton *emailLoginButton; // Continue Via Email // 协议 & 底部文案 @property (nonatomic, strong) UITextView *agreementTextView; // 底部协议富文本 -@property (nonatomic, strong) UILabel *accountTipLabel; // “Already Have An Account?” -@property (nonatomic, strong) UIButton *switchAccountButton; // “Sign In” +//@property (nonatomic, strong) UILabel *accountTipLabel; // “Already Have An Account?” +//@property (nonatomic, strong) UIButton *switchAccountButton; // “Sign In” @end @@ -212,32 +216,32 @@ // 协议文案 [self.scrollContentView addSubview:self.agreementTextView]; [self.agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.equalTo(self.emailLoginButton.mas_bottom).offset(16); + make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16); make.left.equalTo(self.scrollContentView).offset(30); make.right.equalTo(self.scrollContentView).offset(-30); }]; // 底部账号切换文案 - UIView *accountLine = [UIView new]; - [self.scrollContentView addSubview:accountLine]; - [accountLine mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.equalTo(self.agreementTextView.mas_bottom).offset(16); - make.centerX.equalTo(self.scrollContentView); - make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16); - }]; +// UIView *accountLine = [UIView new]; +// [self.scrollContentView addSubview:accountLine]; +// [accountLine mas_makeConstraints:^(MASConstraintMaker *make) { +// make.top.equalTo(self.agreementTextView.mas_bottom).offset(16); +// make.centerX.equalTo(self.scrollContentView); +// make.bottom.equalTo(self.scrollContentView).offset(-KB_SAFE_BOTTOM - 16); +// }]; - [accountLine addSubview:self.accountTipLabel]; - [accountLine addSubview:self.switchAccountButton]; - - [self.accountTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.left.bottom.equalTo(accountLine); - }]; - - [self.switchAccountButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.equalTo(self.accountTipLabel.mas_right).offset(4); - make.right.equalTo(accountLine); - make.centerY.equalTo(self.accountTipLabel); - }]; +// [accountLine addSubview:self.accountTipLabel]; +// [accountLine addSubview:self.switchAccountButton]; +// +// [self.accountTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { +// make.top.left.bottom.equalTo(accountLine); +// }]; +// +// [self.switchAccountButton mas_makeConstraints:^(MASConstraintMaker *make) { +// make.left.equalTo(self.accountTipLabel.mas_right).offset(4); +// make.right.equalTo(accountLine); +// make.centerY.equalTo(self.accountTipLabel); +// }]; } #pragma mark - Actions @@ -265,6 +269,8 @@ - (void)onTapSwitchAccount { // 注册页/登录页互跳逻辑后续接入 KBLOG(@"onTapSwitchAccount"); + KBEmailLoginVC *vc = [[KBEmailLoginVC alloc] init]; + [KB_CURRENT_NAV pushViewController:vc animated:true]; } - (void)onTapTogglePassword:(UIButton *)sender { @@ -279,11 +285,44 @@ } - (void)onTapAppleLogin { - KBLOG(@"onTapAppleLogin in KBEmailRegistVC"); + // 先校验表单:邮箱、密码、重复密码均有值且两次密码一致 + NSString *email = [self.emailTextField.text ?: @"" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *pwd = self.passwordTextField.text ?: @""; + NSString *repeat = self.repeatPasswordTextField.text ?: @""; + + if (email.length == 0 || pwd.length == 0 || repeat.length == 0) { + [KBHUD showInfo:KBLocalized(@"Please complete all fields")]; + return; + } + if (![pwd isEqualToString:repeat]) { + [KBHUD showInfo:KBLocalized(@"The two passwords do not match")]; + return; + } + + KBLOG(@"onTapAppleLogin in KBEmailRegistVC - form validated"); + + // 复用登录页的 Apple 登录逻辑 + [[KBLoginVM shared] signInWithAppleFromViewController:KB_CURRENT_NAV completion:^(BOOL success, NSError * _Nullable error) { + if (success) { + [KBHUD showInfo:KBLocalized(@"Signed in successfully")]; + // 登录成功后切换到主 TabBar + dispatch_async(dispatch_get_main_queue(), ^{ + id appDelegate = UIApplication.sharedApplication.delegate; + if ([appDelegate respondsToSelector:@selector(setupRootVC)]) { + AppDelegate *delegate = (AppDelegate *)appDelegate; + [delegate toMainTabbarVC]; + } + }); + } else { + NSString *msg = error.localizedDescription ?: KBLocalized(@"Sign-in failed"); + [KBHUD showInfo:msg]; + } + }]; } - (void)onTapEmailLogin { KBLOG(@"onTapEmailLogin in KBEmailRegistVC"); + } #pragma mark - Agreement Tap @@ -314,6 +353,11 @@ if (hitTerms || hitPrivacy) { KBLOG(@"tap policy in KBEmailRegistVC"); // 后续可统一跳转到协议页 + if (hitTerms == true) { + [KBHUD showInfo:@"hitTerms"]; + }else{ + [KBHUD showInfo:@"hitPrivacy"]; + } } } @@ -535,7 +579,7 @@ [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _submitButton.titleLabel.font = [KBFont medium:16]; _submitButton.backgroundColor = [UIColor colorWithHex:KBColorValue]; - _submitButton.layer.cornerRadius = 28.0; + _submitButton.layer.cornerRadius = 11.0; _submitButton.layer.masksToBounds = YES; [_submitButton addTarget:self action:@selector(onTapSubmit) @@ -544,22 +588,17 @@ return _submitButton; } -- (UIButton *)appleLoginButton { +- (UIControl *)appleLoginButton { if (!_appleLoginButton) { - _appleLoginButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_appleLoginButton setTitle:KBLocalized(@"Continue Through Apple") forState:UIControlStateNormal]; - [_appleLoginButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal]; - _appleLoginButton.titleLabel.font = [KBFont medium:16]; - _appleLoginButton.backgroundColor = [UIColor whiteColor]; - _appleLoginButton.layer.cornerRadius = 10.0; - _appleLoginButton.layer.masksToBounds = YES; - _appleLoginButton.layer.borderColor = [UIColor colorWithHex:0xE5E5E5].CGColor; - _appleLoginButton.layer.borderWidth = 1; - _appleLoginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; - // 若后续有 Apple 图标资源,可在此设置 imageEdgeInsets 与图标 - [_appleLoginButton addTarget:self - action:@selector(onTapAppleLogin) - forControlEvents:UIControlEventTouchUpInside]; + ASAuthorizationAppleIDButton *btn = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeSignIn + style:ASAuthorizationAppleIDButtonStyleWhite]; + [btn addTarget:self action:@selector(onTapAppleLogin) forControlEvents:UIControlEventTouchUpInside]; + btn.cornerRadius = 10.0; + btn.layer.borderColor = [UIColor colorWithHex:0xE5E5E5].CGColor; + btn.layer.borderWidth = 1; + btn.layer.cornerRadius = 10.0; + btn.layer.masksToBounds = true; + _appleLoginButton = btn; } return _appleLoginButton; } @@ -569,7 +608,7 @@ _emailLoginButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_emailLoginButton setTitle:KBLocalized(@"Continue Via Email") forState:UIControlStateNormal]; [_emailLoginButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal]; - _emailLoginButton.titleLabel.font = [KBFont medium:16]; + _emailLoginButton.titleLabel.font = [KBFont medium:19]; _emailLoginButton.backgroundColor = [UIColor whiteColor]; _emailLoginButton.layer.cornerRadius = 10.0; _emailLoginButton.layer.masksToBounds = YES; @@ -656,27 +695,27 @@ return _agreementTextView; } -- (UILabel *)accountTipLabel { - if (!_accountTipLabel) { - _accountTipLabel = [UILabel new]; - _accountTipLabel.text = KBLocalized(@"Already Have An Account?"); - _accountTipLabel.font = [KBFont regular:10]; - _accountTipLabel.textColor = [UIColor colorWithHex:KBBlackValue]; - } - return _accountTipLabel; -} - -- (UIButton *)switchAccountButton { - if (!_switchAccountButton) { - _switchAccountButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_switchAccountButton setTitle:KBLocalized(@"Sign In") forState:UIControlStateNormal]; - [_switchAccountButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; - _switchAccountButton.titleLabel.font = [KBFont medium:10]; - [_switchAccountButton addTarget:self - action:@selector(onTapSwitchAccount) - forControlEvents:UIControlEventTouchUpInside]; - } - return _switchAccountButton; -} +//- (UILabel *)accountTipLabel { +// if (!_accountTipLabel) { +// _accountTipLabel = [UILabel new]; +// _accountTipLabel.text = KBLocalized(@"Already Have An Account?"); +// _accountTipLabel.font = [KBFont regular:10]; +// _accountTipLabel.textColor = [UIColor colorWithHex:KBBlackValue]; +// } +// return _accountTipLabel; +//} +// +//- (UIButton *)switchAccountButton { +// if (!_switchAccountButton) { +// _switchAccountButton = [UIButton buttonWithType:UIButtonTypeCustom]; +// [_switchAccountButton setTitle:KBLocalized(@"Sign In") forState:UIControlStateNormal]; +// [_switchAccountButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; +// _switchAccountButton.titleLabel.font = [KBFont medium:10]; +// [_switchAccountButton addTarget:self +// action:@selector(onTapSwitchAccount) +// forControlEvents:UIControlEventTouchUpInside]; +// } +// return _switchAccountButton; +//} @end