123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- //
- // YMAdolescentModelTipsViewController.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/22.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAdolescentModelViewController.h"
- #import "YMAdolescentModelViewModel.h"
- #import "YMAdolescentModelTipsView.h"
- #import "YMAdolescentModelPasswordView.h"
- @interface YMAdolescentModelViewController ()
- /// 青少年模式提示VM
- @property (nonatomic, strong) YMAdolescentModelViewModel *viewModel;
- /// 容器滚动视图
- @property (nonatomic, strong) UIScrollView *contentScrollView;
- /// 容器视图
- @property (nonatomic, strong) UIView *contentView;
- /// 青少年模式提示视图
- @property (nonatomic, strong) YMAdolescentModelTipsView *adolescentModelTipsView;
- /// 青少年模式密码视图
- @property (nonatomic, strong) YMAdolescentModelPasswordView *adolescentModelPasswordView;
- /// 青少年模式操作按钮
- @property (nonatomic, strong) UIButton *adolescentModelOperationBtn;
- @end
- @implementation YMAdolescentModelViewController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- }
- - (void)ym_setupViews{
- [self.view addSubview:self.contentScrollView];
- [self.contentScrollView addSubview:self.contentView];
-
- switch (self.viewModel.adolescentModelType) {
- case YMAdolescentModelTypeTips:
- {
- [self.contentView addSubview:self.adolescentModelTipsView];
- }
- break;
- case YMAdolescentModelTypeSettingPassword:
- case YMAdolescentModelTypeConfirmPassword:
- case YMAdolescentModelTypeClosePassword:
- {
- [self.contentView addSubview:self.adolescentModelPasswordView];
- }
- break;
- default:
- break;
- }
-
- [self.view addSubview:self.adolescentModelOperationBtn];
- [self.view setNeedsUpdateConstraints];
- [self.view updateConstraintsIfNeeded];
- }
- - (void)updateViewConstraints{
-
- [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(kYMNavHeight);
- make.left.equalTo(self.view);
- make.right.equalTo(self.view);
- }];
-
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentScrollView);
- make.width.equalTo(self.contentScrollView.mas_width);
- }];
-
- switch (self.viewModel.adolescentModelType) {
- case YMAdolescentModelTypeTips:
- {
- [self.adolescentModelTipsView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.bottom.equalTo(self.contentView);
- }];
-
-
- }
- break;
- case YMAdolescentModelTypeSettingPassword:
- case YMAdolescentModelTypeConfirmPassword:
- case YMAdolescentModelTypeClosePassword:
- {
- [self.adolescentModelPasswordView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.bottom.equalTo(self.contentView);
- }];
- }
- break;
- default:
- break;
- }
-
- [self.adolescentModelOperationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentScrollView.mas_bottom).offset(adapt(10));
- make.left.equalTo(self.view).offset(adapt(30));
- make.right.equalTo(self.view).offset(adapt(-30));
- make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
- make.height.mas_equalTo(adapt(50));
- }];
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel{
-
- [self.adolescentModelTipsView ym_bindViewModel:self.viewModel];
- [self.adolescentModelPasswordView ym_bindViewModel:self.viewModel];
-
- @weakify(self)
- [[[[RACObserve(self.viewModel, adolescentModelOperationText) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * adolescentModelOperationText) {
- @strongify(self)
- [self.adolescentModelOperationBtn setTitle:adolescentModelOperationText forState:UIControlStateNormal];
- }];
-
-
- }
- - (UIScrollView *)contentScrollView{
- if (!_contentScrollView) {
- _contentScrollView = [[UIScrollView alloc]init];
- _contentScrollView.alwaysBounceVertical = YES;
- _contentScrollView.showsVerticalScrollIndicator = NO;
- _contentScrollView.showsHorizontalScrollIndicator = NO;
- _contentScrollView.backgroundColor = HexColorFromRGB(0xFFFFFF);
- _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
- }
- return _contentScrollView;
- }
- - (UIView *)contentView{
- if (!_contentView) {
- _contentView = [[UIView alloc]init];
- }
- return _contentView;
- }
- - (YMAdolescentModelTipsView *)adolescentModelTipsView{
- if (!_adolescentModelTipsView) {
- _adolescentModelTipsView = [[YMAdolescentModelTipsView alloc]init];
- }
- return _adolescentModelTipsView;
- }
- - (YMAdolescentModelPasswordView *)adolescentModelPasswordView{
- if (!_adolescentModelPasswordView) {
- _adolescentModelPasswordView = [[YMAdolescentModelPasswordView alloc]init];
- }
- return _adolescentModelPasswordView;
- }
- - (UIButton *)adolescentModelOperationBtn{
- if (!_adolescentModelOperationBtn) {
- _adolescentModelOperationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _adolescentModelOperationBtn.titleLabel.font = LCFont(15);
- [_adolescentModelOperationBtn setTitle:@"开启青少年模式" forState:UIControlStateNormal];
- [_adolescentModelOperationBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
- [_adolescentModelOperationBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
- _adolescentModelOperationBtn.layer.cornerRadius = adapt(8);
- _adolescentModelOperationBtn.layer.masksToBounds = YES;
- WS(weakSelf)
- [[[_adolescentModelOperationBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- switch (weakSelf.viewModel.adolescentModelType) {
- case YMAdolescentModelTypeTips:
- {
- YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMAdolescentModelTypeSettingPassword)
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
- RouterViewModel:adolescentModelVM
- } completion:nil];
- }
- break;
- case YMAdolescentModelTypeSettingPassword:
- {
- if (weakSelf.viewModel.adolescentModelSettingPassword.length <= 3) {
- [ZCHUDHelper showTitle:@"请设置4位数密码"];
- return;
- }
- YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMAdolescentModelTypeConfirmPassword),
- @"settingPassword":weakSelf.viewModel.adolescentModelSettingPassword
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
- RouterViewModel:adolescentModelVM
- } completion:nil];
- }
- break;
- case YMAdolescentModelTypeConfirmPassword:
- {
- if (![weakSelf.viewModel.adolescentModelSettingPassword isEqualToString:weakSelf.viewModel.adolescentModelConfirmPassword]) {
- [ZCHUDHelper showTitle:@"密码不正确"];
- return;
- }
- [weakSelf.viewModel openAdolescentModel];
- }
- break;
- case YMAdolescentModelTypeClosePassword:
- {
- if (OCStringIsEmpty(weakSelf.viewModel.adolescentModelConfirmPassword)) {
- [ZCHUDHelper showTitle:@"密码不正确"];
- return;
- }
- [self.viewModel closeAdolescentModel];
- }
- break;
- default:
- break;
- }
- }];
- }
- return _adolescentModelOperationBtn;
- }
- @end
|