热更新demo

forgetPwdConfirmController.m 11KB

    // // forgetPwdConfirmController.m // ThePaperBase // // Created by Huixin on 15/8/20. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "forgetPwdConfirmController.h" #import "userSystemViewModel.h" #import "confimPwdController.h" @interface forgetPwdConfirmController () <UITextFieldDelegate, userSystemViewModel> @property(nonatomic, strong)UIImageView *userImageView; @property(nonatomic, strong)UITextField *userField; @property(nonatomic, strong)UIView *userLine; @property(nonatomic, strong)UIImageView *verificationCodeImageView; @property(nonatomic, strong)UITextField *verificationCodeField; @property(nonatomic, strong)UIView *verificationCodeLine; @property(nonatomic, strong)UIButton *getCodeBtn; @property(nonatomic, strong)TPCustomButton *confirmBtn; @property(nonatomic, strong)userSystemViewModel *viewModel; @end @implementation forgetPwdConfirmController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleStr = @"忘记密码"; _viewModel = [userSystemViewModel new]; _viewModel.delegate = self; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; [self.view addGestureRecognizer:tapGesture]; [self.view addSubview:self.userField]; [self.view addSubview:self.userImageView]; [self.view addSubview:self.userLine]; [self.view addSubview:self.getCodeBtn]; [self.view addSubview:self.verificationCodeImageView]; [self.view addSubview:self.verificationCodeField]; [self.view addSubview:self.verificationCodeLine]; [self.view addSubview:self.confirmBtn]; [self.userField becomeFirstResponder]; if (![TPUserDefault instance].fogetPwdInfoBO) { [TPUserDefault instance].fogetPwdInfoBO = registerInfoBO.new; } [self layoutViews]; } - (void)layoutViews { [self.userImageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left).offset(20); make.bottom.equalTo(self.userField.bottom); make.width.mas_equalTo(@20); make.height.mas_equalTo(@19); }]; [self.userField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.naviBar.bottom).offset(38); make.left.equalTo(self.view.left).offset(50); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.userLine makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userField.bottom).offset(7); make.left.equalTo(self.userImageView.left); make.right.equalTo(self.userField.right); make.height.mas_equalTo(@1); }]; [self.getCodeBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userLine.bottom).offset(30); make.centerX.equalTo(self.view.centerX); make.width.mas_equalTo(@80); make.height.mas_equalTo(@20); }]; [self.verificationCodeImageView makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.verificationCodeField.centerY); make.left.equalTo(self.view.left).offset(20); make.width.mas_equalTo(@20); make.height.mas_equalTo(@15); }]; [self.verificationCodeField makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.getCodeBtn.bottom).offset(38); make.left.equalTo(self.view.left).offset(50); make.right.equalTo(self.view.right).offset(-20); make.height.mas_equalTo(@19); }]; [self.verificationCodeLine makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.verificationCodeField.bottom).offset(7); make.left.equalTo(self.verificationCodeImageView.left); make.right.equalTo(self.verificationCodeField.right); make.height.mas_equalTo(@1); }]; [self.confirmBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.verificationCodeLine.bottom).offset(35); make.left.equalTo(self.view.left).offset(20); make.right.equalTo(self.view.right).offset(-20); make.height.equalTo(self.confirmBtn.width).multipliedBy(0.15); }]; } #pragma mark - get method - (UIImageView*)userImageView { if (!_userImageView) { _userImageView = [[UIImageView alloc] init]; _userImageView.image = Image(@"login/userName.png"); } return _userImageView; } - (UITextField*)userField { if (!_userField) { _userField = [[UITextField alloc] init]; _userField.backgroundColor = [UIColor clearColor]; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入注册时的手机或电子邮箱" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _userField.attributedPlaceholder = atrString; _userField.textColor = [UIColor colorWithHexString:TextBlack]; _userField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _userField.textAlignment = NSTextAlignmentLeft; _userField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _userField.keyboardAppearance = UIKeyboardAppearanceDark; } _userField.keyboardType = UIKeyboardTypeEmailAddress; _userField.clearButtonMode = UITextFieldViewModeWhileEditing; _userField.delegate = self; [_userField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; } return _userField; } - (UIView*)userLine { if (!_userLine) { _userLine = [[UIView alloc] init]; _userLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _userLine; } - (UIButton*)getCodeBtn { if (!_getCodeBtn) { _getCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_getCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; [_getCodeBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; [_getCodeBtn setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted]; _getCodeBtn.titleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _getCodeBtn.layer.borderColor = [UIColor colorWithHexString:BLUECOLOR].CGColor; _getCodeBtn.layer.cornerRadius = 4.f; _getCodeBtn.layer.borderWidth = 1; [_getCodeBtn addTarget:self action:@selector(getVerificationCode:) forControlEvents:UIControlEventTouchUpInside]; } return _getCodeBtn; } - (UIImageView*)verificationCodeImageView { if (!_verificationCodeImageView) { _verificationCodeImageView = [[UIImageView alloc] init]; _verificationCodeImageView.image = Image(@"login/pin.png"); } return _verificationCodeImageView; } - (UITextField*)verificationCodeField { if (!_verificationCodeField) { _verificationCodeField = [[UITextField alloc] init]; _verificationCodeField.backgroundColor = [UIColor clearColor]; NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入您收到的验证码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}]; _verificationCodeField.attributedPlaceholder = atrString; _verificationCodeField.textColor = [UIColor colorWithHexString:TextBlack]; _verificationCodeField.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _verificationCodeField.textAlignment = NSTextAlignmentLeft; _verificationCodeField.keyboardAppearance = UIKeyboardAppearanceDefault; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _verificationCodeField.keyboardAppearance = UIKeyboardAppearanceDark; } _verificationCodeField.keyboardType = UIKeyboardTypeNumberPad; _verificationCodeField.clearButtonMode = UITextFieldViewModeWhileEditing; _verificationCodeField.delegate = self; [_verificationCodeField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; } return _verificationCodeField; } - (UIView*)verificationCodeLine { if (!_verificationCodeLine) { _verificationCodeLine = [[UIView alloc] init]; _verificationCodeLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _verificationCodeLine; } - (TPCustomButton*)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[TPCustomButton alloc] init]; _confirmBtn.title = @"确认"; [_confirmBtn addTarget:self action:@selector(confirmEvent) forControlEvents:UIControlEventTouchUpInside]; } return _confirmBtn; } #pragma mark - textfield delegate - (void)textFieldDidChange:(UITextField *)textField { if ([textField.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) { textField.text = disable_emoji(textField.text); } if (textField == self.userField) { [TPUserDefault instance].fogetPwdInfoBO.mail = textField.text; }else if (textField == self.verificationCodeField) { [TPUserDefault instance].fogetPwdInfoBO.verCode = textField.text; } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == _userField) { [_verificationCodeField becomeFirstResponder]; } else if (textField == _verificationCodeField) { [self confirmEvent]; } return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([textField isFirstResponder]) { if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) { return NO; } } return YES; } #pragma mark - btn event handler - (void)getVerificationCode:(UIButton*)btn { [self closeKeyBoard]; [_viewModel getVerifyCode]; } - (void)confirmEvent { [self closeKeyBoard]; [_viewModel confirmVerifyCode]; } #pragma mark - viewmodel delegate - (void)confirmVerifyCodeSuccess { confimPwdController *vc = [confimPwdController new]; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark - tap handler - (void)tap:(UITapGestureRecognizer*)sender { [self closeKeyBoard]; } #pragma mark - keyBoard event - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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. } */ @end