| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- //
- // ResetPassword_VC.m
- // Haishenghai-master
- //
- // Created by GG on 2018/12/30.
- // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "ResetPassword_VC.h"
- #import "Header.h"
- @interface ResetPassword_VC ()<UITextFieldDelegate>
- @end
- @implementation ResetPassword_VC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title = @"重设密码";
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1]}];
- //设置导航栏左侧按钮
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(0, 0, 44, 44);
- [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
- backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
-
- [self setupUI];
- }
- #pragma mark -Set UI
- -(void)setupUI{
- /** 设置背景 */
- self.view.backgroundColor = [UIColor whiteColor];
-
- /** 设置返回 */
- // self.backBtn.frame = CGRectMake(10, 20, 30, 30);
- // [self.backBtn setBackgroundImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
- // [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
- // [self.view addSubview:self.backBtn];
- /**返回label */
- // self.backLabel.frame = CGRectMake(40, 20, 60, 30);
- // self.backLabel.text = @"返回";
- //// self.backLabel.textAlignment = NSTextAlignmentCenter;
- // self.backLabel.font = [UIFont systemFontOfSize:18];
- // [self.view addSubview:self.backLabel];
-
- /** 设置logo */
- [self.logoImageView setImage:[UIImage imageNamed:@"logo"]];
- self.logoImageView.frame = CGRectMake(WIDTH/2-55, HEIGHT/4-75, 110, 110);
- [self.view addSubview:self.logoImageView];
-
- /** 设置内容视图 */
-
- /**设置账户输入框 */
- self.accountTF.frame = CGRectMake(20, HEIGHT/2-64, WIDTH-40, 44);
- self.accountTF.placeholder = @"请输入注册手机号";
- self.accountTF.tintColor = [UIColor blueColor];
- self.accountTF.textColor = [UIColor blackColor];
- self.accountTF.font = [UIFont systemFontOfSize:18];
- self.accountTF.leftViewMode = UITextFieldViewModeAlways;
- self.accountTF.clearsOnBeginEditing = YES;
- self.accountTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.accountTF.autocorrectionType =UITextAutocorrectionTypeDefault;
- self.accountTF.delegate = self;
- //设置左边视图
- UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- userImage.contentMode = UIViewContentModeLeft;
- //??
- userImage.image = [UIImage imageNamed:@"hsh_login_user"];
- self.accountTF.leftView = userImage;
- [self.view addSubview:self.accountTF];
- UIView *accountLine = [[UIView alloc]init];
- //??
- accountLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- accountLine.backgroundColor = [UIColor grayColor];
- self.accountLine = accountLine;
- [self.accountTF addSubview:accountLine];
-
- /** 设置验证码输入框 */
- self.smsCodeTF.frame = CGRectMake(20, HEIGHT/2-20, WIDTH-40, 44);
- self.smsCodeTF.placeholder = @"请输入手机验证码";
- self.smsCodeTF.tintColor = [UIColor blueColor];
- self.smsCodeTF.textColor = [UIColor blackColor];
- self.smsCodeTF.font = [UIFont systemFontOfSize:18];
- self.smsCodeTF.leftViewMode = UITextFieldViewModeAlways;
- // self.smsCodeTF.clearsOnBeginEditing = YES;
- // self.smsCodeTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.smsCodeTF.autocorrectionType =UITextAutocorrectionTypeDefault;
- self.smsCodeTF.delegate = self;
- //设置左边视图
- UIImageView *smsImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- smsImage.contentMode = UIViewContentModeLeft;
- smsImage.image = [UIImage imageNamed:@"hsh_register_verification"];
- self.smsCodeTF.leftView = smsImage;
- [self.view addSubview:self.smsCodeTF];
- UIView *smsLine = [[UIView alloc]init];
- //??
- smsLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- smsLine.backgroundColor = [UIColor grayColor];
- self.smsLine = smsLine;
- [self.smsCodeTF addSubview:self.smsLine];
-
- /**设置重置密码button */
- self.resetPasswordBtn.frame = CGRectMake(self.smsCodeTF.frame.size.width-100, 5, 100, 34);
- self.resetPasswordBtn.layer.cornerRadius = 12;
- self.resetPasswordBtn.backgroundColor = [UIColor colorWithRed:113/255.0 green:154/255.90 blue:254/255.0 alpha:1];
- [self.resetPasswordBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
- [self.resetPasswordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.resetPasswordBtn.titleLabel.textColor = [UIColor whiteColor];
- self.resetPasswordBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- self.resetPasswordBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
- [self.resetPasswordBtn addTarget:self action:@selector(getSMSCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.smsCodeTF addSubview:self.resetPasswordBtn];
-
- /**设置密码输入框 */
- self.passwordTF.frame = CGRectMake(20, HEIGHT/2+22, WIDTH-40, 44);
- self.passwordTF.placeholder = @"请输入新密码";
- self.passwordTF.tintColor = [UIColor blueColor];
- self.passwordTF.textColor = [UIColor blackColor];
- self.passwordTF.font = [UIFont systemFontOfSize:18];
- self.passwordTF.leftViewMode = UITextFieldViewModeAlways;
- self.passwordTF.delegate = self;
- self.passwordTF.clearsOnBeginEditing = YES;
- self.passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.passwordTF.autocorrectionType =UITextAutocorrectionTypeDefault;
- self.passwordTF.secureTextEntry =YES;
- //设置左边视图
- UIImageView *passwordImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- passwordImage.contentMode = UIViewContentModeLeft;
- passwordImage.image = [UIImage imageNamed:@"hsh_login_password"];
- self.passwordTF.leftView = passwordImage;
- [self.view addSubview:self.passwordTF];
- UIView *passwordLine = [[UIView alloc]init];
- //??
- passwordLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- passwordLine.backgroundColor = [UIColor grayColor];
- self.passwordLine = passwordLine;
- [self.passwordTF addSubview:passwordLine];
-
- /** 设置确认密码 */
- self.confirmPasswordTf.frame = CGRectMake(20, HEIGHT/2+66, WIDTH-40, 44);
- self.confirmPasswordTf.placeholder = @"请再次确认密码";
- self.confirmPasswordTf.tintColor = [UIColor blueColor];
- self.confirmPasswordTf.textColor = [UIColor blackColor];
- self.confirmPasswordTf.font = [UIFont systemFontOfSize:18];
- self.confirmPasswordTf.leftViewMode = UITextFieldViewModeAlways;
- self.confirmPasswordTf.delegate = self;
- self.confirmPasswordTf.clearsOnBeginEditing = YES;
- self.confirmPasswordTf.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.confirmPasswordTf.autocorrectionType =UITextAutocorrectionTypeDefault;
- self.confirmPasswordTf.secureTextEntry =YES;
- //设置左边视图
- UIImageView *confirmImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
- confirmImage.contentMode = UIViewContentModeLeft;
- confirmImage.image = [UIImage imageNamed:@"hsh_login_password"];
- self.confirmPasswordTf.leftView = confirmImage;
- [self.view addSubview:self.confirmPasswordTf];
- UIView *confirmLine = [[UIView alloc]init];
- //??
- confirmLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
- confirmLine.backgroundColor = [UIColor grayColor];
- self.confirmLine = confirmLine;
- [self.confirmPasswordTf addSubview:self.confirmLine];
-
-
- /**设置提交Button */
- self.registButton.frame = CGRectMake(20, HEIGHT-100, WIDTH-40, 44);
- self.registButton.layer.cornerRadius = 18;
- [self.registButton setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal];
- [self.registButton setTitle:@"提交" forState:UIControlStateNormal];
- [self.registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.registButton.titleLabel.font = [UIFont systemFontOfSize:18];
- self.registButton.titleLabel.textAlignment = NSTextAlignmentCenter;
- // self.loginButton.clipsToBounds = YES;
- [self.registButton addTarget:self action:@selector(comitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.registButton];
-
-
- /** 布局 */
- [self make_layout];
- }
- -(void)make_layout{
-
- }
- #pragma mark - Event response
- -(void)backBtnClick{
- [self.navigationController popViewControllerAnimated:YES];
-
- }
- -(void)getSMSCodeBtnClick:(UIButton *)codeBtn{
- // if (self.accountTF.text==nil||self.accountTF.text.length<11||self.accountTF.text.length>11) {
- // ALERTSHOW(@"手机号有误,请重新输入");
- // }
- [self startTime];
- }
- -(void)startTime{
- // GCD类型
- __block int timeout=59; //倒计时时间
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
-
- dispatch_source_set_event_handler(_timer, ^{
- if(timeout<=0){ //倒计时结束,关闭
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置(倒计时结束后调用)
- //设置按钮的样式
- [self.resetPasswordBtn setTitle:@"重新发送" forState:UIControlStateNormal];
- //设置不可点击
- self.resetPasswordBtn.userInteractionEnabled = YES;
-
- });
- }else{
- // int minutes = timeout / 60; //这里注释掉了,这个是用来测试多于60秒时计算分钟的。
- int seconds = timeout % 60;
- NSString *strTime = [NSString stringWithFormat:@"%ds", seconds];
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- // NSLog(@"____%@",strTime);
- [self.resetPasswordBtn setTitle:[NSString stringWithFormat:@"%@秒重发",strTime] forState:UIControlStateNormal];
- //设置可点击
- self.resetPasswordBtn.userInteractionEnabled = NO;
- });
- timeout--;
- }
- });
-
- dispatch_resume(_timer);
- //请求验证码
- [DataSourceManager getPhoneCodeWithPhone:self.accountTF.text completionBlock:^(NSDictionary *dic) {
- ALERTSHOW(@"验证码发送成功");
- }];
- }
- -(void)comitBtnClick:(UIButton *)comitBtn{
- [self show];
- //提交修改
- [DataSourceManager updatePasswordWithUrlPhone:self.accountTF.text code:self.smsCodeTF.text Password1:self.passwordTF.text Password2:self.confirmPasswordTf.text completionBlock:^(NSDictionary *dic) {
- ALERTSHOW(@"修改密码成功");
- }];
- }
- #pragma mark------用户名密码校验
- -(void)show{
- if (self.accountTF.text ==nil||self.accountTF.text.length<11||self.accountTF.text.length >11) {
- [self.loginButton setEnabled:NO];
- [self.registButton setEnabled:NO];
- ALERTSHOW(@"手机号输入有误");
- return;
- }
-
- if (self.passwordTF.text ==nil||self.passwordTF.text.length>8){
- [self.loginButton setEnabled:NO];
- [self.registButton setEnabled:NO];
- ALERTSHOW(@"密码输入有误");
- return;
- }
- if (![self.passwordTF.text isEqualToString:self.confirmPasswordTf.text]) {
- ALERTSHOW(@"两次输入密码不相同");
- return;
- }
- }
- #pragma mark - Delegate methods
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- return YES;
- }
- //避免键盘遮挡,登录表单或按钮上移代码
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
-
- //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
- self.view.frame = CGRectMake(0.0f, -50.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
-
- [UIView commitAnimations];
-
- return YES;
-
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
-
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
- //恢复屏幕
- self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
-
- [UIView commitAnimations];
- [[UIApplication sharedApplication].keyWindow endEditing:YES];
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- - (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
|