// // YMSelectedLoginViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/4. // Copyright © 2024 MS. All rights reserved. // #import "YMSelectedLoginViewController.h" #import "YMSelectedLoginViewModel.h" @interface YMSelectedLoginViewController () /// 选择登录VM @property (nonatomic, strong) YMSelectedLoginViewModel *viewModel; /// 启动图 @property (nonatomic, strong) UIImageView *launchscreenImage; /// 验证码登录 @property (nonatomic, strong) UIButton *verifyCodeLoginBtn; /// 密码登录 @property (nonatomic, strong) UIButton *passwordLoginBtn; /// 协议视图 @property (nonatomic, strong) UIView *agreementView; /// 单选按钮 @property (nonatomic, strong) UIButton *radioBtn; /// 协议标签 @property (nonatomic, strong) YYLabel *agreementLb; @end @implementation YMSelectedLoginViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; [self.navigationController setNavigationBarHidden:YES animated:YES]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:YES]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } - (void)ym_setupViews{ [self.view addSubview:self.launchscreenImage]; [self.launchscreenImage addSubview:self.verifyCodeLoginBtn]; [self.launchscreenImage addSubview:self.passwordLoginBtn]; [self.launchscreenImage addSubview:self.agreementView]; [self.agreementView addSubview:self.radioBtn]; [self.agreementView addSubview:self.agreementLb]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.launchscreenImage mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).priority(1000); make.left.right.equalTo(self.view); make.bottom.equalTo(self.view).priority(1000); }]; [self.verifyCodeLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.launchscreenImage.mas_centerX); make.bottom.equalTo(self.launchscreenImage.mas_centerY).offset(adapt(-20)); make.left.mas_equalTo(self.launchscreenImage).offset(adapt(25)); make.right.mas_equalTo(self.launchscreenImage).offset(adapt(-25)); make.height.mas_equalTo(adapt(45)); }]; [self.passwordLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.launchscreenImage.mas_centerX); make.top.equalTo(self.launchscreenImage.mas_centerY).offset(adapt(20)); make.left.mas_equalTo(self.launchscreenImage).offset(adapt(25)); make.right.mas_equalTo(self.launchscreenImage).offset(adapt(-25)); make.height.mas_equalTo(45); }]; [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.launchscreenImage.mas_centerX); make.bottom.equalTo(self.launchscreenImage).offset(Is_iPhoneX ? adapt(-32) : adapt(-12)); }]; [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.agreementLb.mas_centerY); make.left.equalTo(self.agreementView).offset(adapt(5)); make.width.height.mas_equalTo(adapt(12)); }]; [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.agreementView).offset(adapt(10)); make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5)); make.right.equalTo(self.agreementView).offset(adapt(-5)); make.bottom.equalTo(self.agreementView).offset(adapt(-10)); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ } - (UIImageView *)launchscreenImage{ if (!_launchscreenImage) { _launchscreenImage = [[UIImageView alloc]init]; _launchscreenImage.contentMode = UIViewContentModeScaleAspectFill; _launchscreenImage.image = ImageByName(@"vqu_images_ic_login_bg"); _launchscreenImage.userInteractionEnabled = YES; } return _launchscreenImage; } - (UIButton *)verifyCodeLoginBtn{ if (!_verifyCodeLoginBtn) { _verifyCodeLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _verifyCodeLoginBtn.backgroundColor = HexColorFromRGB(0xF888E7); _verifyCodeLoginBtn.titleLabel.font = LCFont(15); [_verifyCodeLoginBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; [_verifyCodeLoginBtn setTitle:@"手机号登录" forState:UIControlStateNormal]; _verifyCodeLoginBtn.layer.cornerRadius = adapt(8); WS(weakSelf) [[[_verifyCodeLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { if (!weakSelf.radioBtn.selected) { YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; [popupView pop]; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { weakSelf.radioBtn.selected = YES; [weakSelf.viewModel gotoLoginVC:LoginCategoryTypeVerifyCode]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; customView.dismissBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; return; } [weakSelf.viewModel gotoLoginVC:LoginCategoryTypeVerifyCode]; }]; } return _verifyCodeLoginBtn; } - (UIButton *)passwordLoginBtn{ if (!_passwordLoginBtn) { _passwordLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _passwordLoginBtn.backgroundColor = HexColorFromRGB(0xF888E7); _passwordLoginBtn.titleLabel.font = LCFont(15); [_passwordLoginBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; [_passwordLoginBtn setTitle:@"密码登录" forState:UIControlStateNormal]; _passwordLoginBtn.layer.cornerRadius = adapt(8); WS(weakSelf) [[[_passwordLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { if (!weakSelf.radioBtn.selected) { YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; [popupView pop]; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { weakSelf.radioBtn.selected = YES; [weakSelf.viewModel gotoLoginVC:LoginCategoryTypePassword]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; customView.dismissBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; return; } [weakSelf.viewModel gotoLoginVC:LoginCategoryTypePassword]; }]; } return _passwordLoginBtn; } - (UIView *)agreementView{ if (!_agreementView) { _agreementView = [[UIView alloc]init]; } return _agreementView; } - (UIButton *)radioBtn{ if (!_radioBtn) { _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal]; [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected]; [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { sender.selected = !sender.selected; }]; } return _radioBtn; } - (YYLabel *)agreementLb{ if (!_agreementLb) { _agreementLb = [[YYLabel alloc] init]; _agreementLb.numberOfLines = 0; _agreementLb.preferredMaxLayoutWidth = kFrameWidth - adapt(55); NSString *agreementText = @"我已阅读并同意《用户协议》和《隐私协议》"; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; paragraphStyle.alignment = NSTextAlignmentLeft; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText]; attributedString.yy_font = LCFont(11); attributedString.yy_color = HexColorFromRGB(0x7E848D); attributedString.yy_paragraphStyle = paragraphStyle; //设置高亮色和点击事件 [attributedString yy_setTextHighlightRange:[agreementText rangeOfString:@"《用户协议》"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; //设置高亮色和点击事件 [attributedString yy_setTextHighlightRange:[[attributedString string] rangeOfString:@"《隐私协议》"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; _agreementLb.attributedText = attributedString; } return _agreementLb; } @end