UserRegister_VC.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. //
  2. // UserRegister_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2018/12/29.
  6. // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "UserRegister_VC.h"
  9. #import "Header.h"
  10. #import "privacy_VC.h"
  11. #import "Protcol_VC.h"
  12. @interface UserRegister_VC ()<UITextFieldDelegate>
  13. @end
  14. @implementation UserRegister_VC
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. //导航栏添加返回按钮
  18. self.navigationItem.title = @"注册";
  19. //改变返回按钮的箭头和颜色
  20. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1]}];
  21. //设置导航栏左侧按钮
  22. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  23. [backBtn setImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
  24. backBtn.frame = CGRectMake(0, 0, 44, 44);
  25. [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
  26. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  27. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  28. //
  29. [self setupUI];
  30. }
  31. #pragma mark -Set UI
  32. -(void)setupUI{
  33. /** 设置背景 */
  34. self.view.backgroundColor = [UIColor whiteColor];
  35. /** 设置返回 */
  36. // self.backBtn.frame = CGRectMake(10, 20, 30, 30);
  37. // [self.backBtn setBackgroundImage:[UIImage imageNamed:@"hsh_register_return"] forState:UIControlStateNormal];
  38. // [self.backBtn setTitle:@"返回" forState:UIControlStateNormal];
  39. // [self.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
  40. // [self.view addSubview:self.backBtn];
  41. /** 设置logo */
  42. [self.logoImageView setImage:[UIImage imageNamed:@"logo"]];
  43. self.logoImageView.frame = CGRectMake(WIDTH/2-55, HEIGHT/4-75, 110, 110);
  44. [self.view addSubview:self.logoImageView];
  45. /** 设置内容视图 */
  46. /**设置姓名输入框 */
  47. self.accountTF.frame = CGRectMake(20, HEIGHT/2-88, WIDTH-40, 44);
  48. self.accountTF.placeholder = @"请输入昵称";
  49. self.accountTF.tintColor = [UIColor blueColor];
  50. self.accountTF.textColor = [UIColor blackColor];
  51. self.accountTF.font = [UIFont systemFontOfSize:18];
  52. self.accountTF.leftViewMode = UITextFieldViewModeAlways;
  53. self.accountTF.clearsOnBeginEditing = YES;
  54. self.accountTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  55. //自动修正
  56. self.accountTF.autocorrectionType = UITextAutocorrectionTypeDefault;
  57. self.accountTF.delegate = self;
  58. //设置左边视图
  59. UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  60. userImage.contentMode = UIViewContentModeLeft;
  61. //??
  62. userImage.image = [UIImage imageNamed:@"hsh_login_user"];
  63. self.accountTF.leftView = userImage;
  64. [self.view addSubview:self.accountTF];
  65. UIView *accountLine = [[UIView alloc]init];
  66. //??
  67. accountLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  68. accountLine.backgroundColor = [UIColor grayColor];
  69. self.accountLine = accountLine;
  70. [self.accountTF addSubview:accountLine];
  71. /**设置手机号输入框 */
  72. self.phoneTf.frame = CGRectMake(20, HEIGHT/2-44, WIDTH-40, 44);
  73. self.phoneTf.placeholder = @"请输入手机号";
  74. self.phoneTf.tintColor = [UIColor blueColor];
  75. self.phoneTf.textColor = [UIColor blackColor];
  76. self.phoneTf.font = [UIFont systemFontOfSize:18];
  77. self.phoneTf.leftViewMode = UITextFieldViewModeAlways;
  78. self.phoneTf.clearsOnBeginEditing = YES;
  79. self.phoneTf.clearButtonMode =UITextFieldViewModeWhileEditing;
  80. self.phoneTf.autocorrectionType = UITextAutocorrectionTypeDefault;
  81. self.phoneTf.delegate = self;
  82. //设置左边视图
  83. UIImageView *phoneImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  84. phoneImage.contentMode = UIViewContentModeLeft;
  85. phoneImage.image = [UIImage imageNamed:@"hsh_register_tel"];
  86. self.phoneTf.leftView = phoneImage;
  87. [self.view addSubview:self.phoneTf];
  88. UIView *phoneLine = [[UIView alloc]init];
  89. //??
  90. phoneLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  91. phoneLine.backgroundColor = [UIColor grayColor];
  92. _phoneLine = phoneLine;
  93. [self.phoneTf addSubview:self.phoneLine];
  94. /** 设置手机验证码输入框 */
  95. self.smsCodeTF.frame = CGRectMake(20, HEIGHT/2, WIDTH-40, 44);
  96. self.smsCodeTF.placeholder = @"请输入手机验证码";
  97. self.smsCodeTF.tintColor = [UIColor blueColor];
  98. self.smsCodeTF.textColor = [UIColor blackColor];
  99. self.smsCodeTF.font = [UIFont systemFontOfSize:18];
  100. self.smsCodeTF.leftViewMode = UITextFieldViewModeAlways;
  101. // self.smsCodeTF.clearsOnBeginEditing =YES;
  102. // self.smsCodeTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  103. self.smsCodeTF.autocorrectionType = UITextAutocorrectionTypeDefault;
  104. self.smsCodeTF.delegate = self;
  105. //设置左边视图
  106. UIImageView *smsImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  107. smsImage.contentMode = UIViewContentModeLeft;
  108. smsImage.image = [UIImage imageNamed:@"hsh_register_verification"];
  109. self.smsCodeTF.leftView = smsImage;
  110. [self.view addSubview:self.smsCodeTF];
  111. UIView *smsLine = [[UIView alloc]init];
  112. //??
  113. smsLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  114. smsLine.backgroundColor = [UIColor grayColor];
  115. self.smsLine = smsLine;
  116. [self.smsCodeTF addSubview:self.smsLine];
  117. /**设置获取验证码button */
  118. self.resetPasswordBtn.frame = CGRectMake(self.smsCodeTF.frame.size.width-100, 5, 100, 34);
  119. self.resetPasswordBtn.layer.cornerRadius = 12;
  120. self.resetPasswordBtn.backgroundColor = [UIColor colorWithRed:113/255.0 green:154/255.90 blue:254/255.0 alpha:1];
  121. [self.resetPasswordBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  122. [self.resetPasswordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  123. self.resetPasswordBtn.titleLabel.textColor = [UIColor whiteColor];
  124. self.resetPasswordBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  125. self.resetPasswordBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
  126. [self.resetPasswordBtn addTarget:self action:@selector(getSMSCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  127. [self.smsCodeTF addSubview:self.resetPasswordBtn];
  128. /**设置密码输入框 */
  129. self.passwordTF.frame = CGRectMake(20, HEIGHT/2+44, WIDTH-40, 44);
  130. self.passwordTF.placeholder = @"请输入密码";
  131. self.passwordTF.tintColor = [UIColor blueColor];
  132. self.passwordTF.textColor = [UIColor blackColor];
  133. self.passwordTF.font = [UIFont systemFontOfSize:18];
  134. self.passwordTF.leftViewMode = UITextFieldViewModeAlways;
  135. self.passwordTF.delegate = self;
  136. self.passwordTF.secureTextEntry =YES;//密文输入
  137. self.passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
  138. self.passwordTF.autocorrectionType = UITextAutocorrectionTypeDefault;
  139. //设置左边视图
  140. UIImageView *passwordImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  141. passwordImage.contentMode = UIViewContentModeLeft;
  142. //??
  143. passwordImage.image = [UIImage imageNamed:@"hsh_login_password"];
  144. self.passwordTF.leftView = passwordImage;
  145. [self.view addSubview:self.passwordTF];
  146. UIView *passwordLine = [[UIView alloc]init];
  147. //??
  148. passwordLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  149. passwordLine.backgroundColor = [UIColor grayColor];
  150. self.passwordLine = passwordLine;
  151. [self.passwordTF addSubview:passwordLine];
  152. /** 设置确认密码 */
  153. self.confirmPasswordTf.frame = CGRectMake(20, HEIGHT/2+88, WIDTH-40, 44);
  154. self.confirmPasswordTf.placeholder = @"请再次确认密码";
  155. self.confirmPasswordTf.tintColor = [UIColor blueColor];
  156. self.confirmPasswordTf.textColor = [UIColor blackColor];
  157. self.confirmPasswordTf.font = [UIFont systemFontOfSize:18];
  158. self.confirmPasswordTf.leftViewMode = UITextFieldViewModeAlways;
  159. self.confirmPasswordTf.secureTextEntry =YES;
  160. self.confirmPasswordTf.clearButtonMode = UITextFieldViewModeWhileEditing;
  161. self.confirmPasswordTf.autocorrectionType = UITextAutocorrectionTypeDefault;
  162. self.confirmPasswordTf.delegate = self;
  163. //设置左边视图
  164. UIImageView *confirmImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
  165. confirmImage.contentMode = UIViewContentModeLeft;
  166. confirmImage.image = [UIImage imageNamed:@"hsh_login_password"];
  167. self.confirmPasswordTf.leftView = confirmImage;
  168. [self.view addSubview:self.confirmPasswordTf];
  169. UIView *confirmLine = [[UIView alloc]init];
  170. //??
  171. confirmLine.frame = CGRectMake(0, 43.5, WIDTH-40, 0.5);
  172. confirmLine.backgroundColor = [UIColor grayColor];
  173. self.confirmLine = confirmLine;
  174. [self.confirmPasswordTf addSubview:self.confirmLine];
  175. /**设置注册Button */
  176. self.registButton.frame = CGRectMake(20, HEIGHT*0.75, self.view.frame.size.width-40, 44);
  177. self.registButton.layer.cornerRadius = 18;
  178. [self.registButton setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal];
  179. [self.registButton setTitle:@"注册" forState:UIControlStateNormal];
  180. [self.registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  181. self.registButton.titleLabel.font = [UIFont systemFontOfSize:18];
  182. self.registButton.titleLabel.textAlignment = NSTextAlignmentCenter;
  183. // self.loginButton.clipsToBounds = YES;
  184. [self.registButton addTarget:self action:@selector(registeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  185. [self.view addSubview:self.registButton];
  186. //用户协议
  187. UILabel *protcolLabel = [[UILabel alloc]init];
  188. protcolLabel.frame = CGRectMake(WIDTH/2-110, HEIGHT*0.75+44, 110, 30);
  189. // protcolBtn.backgroundColor = [UIColor grayColor];
  190. [self.view addSubview:protcolLabel];
  191. protcolLabel.font = [UIFont systemFontOfSize:12];
  192. protcolLabel.text = @"注册即代表您同意";
  193. protcolLabel.textColor = [UIColor colorWithRed:66/255.0 green:66/255.0 blue:66/255.0 alpha:1];
  194. protcolLabel.textAlignment = NSTextAlignmentRight;
  195. //用户协议Button
  196. UIButton *protcolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  197. protcolBtn.frame =CGRectMake(WIDTH/2, HEIGHT*0.75+44, 60, 30);
  198. [protcolBtn setTitle:@"用户协议" forState:UIControlStateNormal];
  199. [protcolBtn setTitleColor:[UIColor colorWithRed:78/255.0 green:105/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
  200. protcolBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  201. [protcolBtn addTarget:self action:@selector(onBtnClick) forControlEvents:UIControlEventTouchUpInside];
  202. [self.view addSubview:protcolBtn];
  203. //隐私条款Button
  204. UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  205. privateBtn.frame =CGRectMake(WIDTH/2+60, HEIGHT*0.75+44, 60, 30);
  206. [privateBtn setTitle:@"隐私条款" forState:UIControlStateNormal];
  207. [privateBtn setTitleColor:[UIColor colorWithRed:78/255.0 green:105/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
  208. privateBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  209. [privateBtn addTarget:self action:@selector(onBtnClick2) forControlEvents:UIControlEventTouchUpInside];
  210. [self.view addSubview:privateBtn];
  211. /** 布局 */
  212. [self make_layout];
  213. }
  214. -(void)make_layout{
  215. }
  216. #pragma mark - Event response
  217. -(void)onBtnClick{
  218. //用户协议
  219. Protcol_VC *proVC = [[Protcol_VC alloc]init];
  220. [self.navigationController pushViewController:proVC animated:YES];
  221. }
  222. -(void)onBtnClick2{
  223. //隐私条款
  224. privacy_VC *pri = [[privacy_VC alloc]init];
  225. [self.navigationController pushViewController:pri animated:YES];
  226. }
  227. -(void)backBtnClick{
  228. [self.navigationController popViewControllerAnimated:YES];
  229. }
  230. -(void)getSMSCodeBtnClick:(UIButton *)codeBtn{
  231. if (self.phoneTf.text ==nil||self.phoneTf.text.length<11) {
  232. ALERTSHOW(@"手机号输入错误");
  233. return;
  234. }
  235. [self startTime];
  236. }
  237. -(void)startTime{
  238. // GCD类型
  239. __block int timeout=59; //倒计时时间
  240. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  241. dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  242. dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  243. dispatch_source_set_event_handler(_timer, ^{
  244. if(timeout<=0){ //倒计时结束,关闭
  245. dispatch_source_cancel(_timer);
  246. dispatch_async(dispatch_get_main_queue(), ^{
  247. //设置界面的按钮显示 根据自己需求设置(倒计时结束后调用)
  248. //设置按钮的样式
  249. [self.resetPasswordBtn setTitle:@"重新发送" forState:UIControlStateNormal];
  250. //设置不可点击
  251. self.resetPasswordBtn.userInteractionEnabled = YES;
  252. });
  253. }else{
  254. // int minutes = timeout / 60; //这里注释掉了,这个是用来测试多于60秒时计算分钟的。
  255. int seconds = timeout % 60;
  256. NSString *strTime = [NSString stringWithFormat:@"%ds", seconds];
  257. dispatch_async(dispatch_get_main_queue(), ^{
  258. //设置界面的按钮显示 根据自己需求设置
  259. NSLog(@"____%@",strTime);
  260. [self.resetPasswordBtn setTitle:[NSString stringWithFormat:@"%@秒重发",strTime] forState:UIControlStateNormal];
  261. //设置可点击
  262. self.resetPasswordBtn.userInteractionEnabled = NO;
  263. });
  264. timeout--;
  265. }
  266. });
  267. dispatch_resume(_timer);
  268. //请求验证码
  269. [DataSourceManager getPhoneCodeWithPhone:self.phoneTf.text completionBlock:^(NSDictionary *dic) {
  270. ALERTSHOW(@"验证码发送成功");
  271. }];
  272. }
  273. -(void)registeBtnClick:(UIButton *)registBtn{
  274. [self show];
  275. [DataSourceManager setRegisterWithUrlPhoneNumber:self.phoneTf.text code:self.smsCodeTF.text UserName:self.accountTF.text PassWord1:self.passwordTF.text PassWord2:self.confirmPasswordTf.text completionBlock:^(NSDictionary *dic) {
  276. ALERTSHOW(@"注册成功");
  277. }];
  278. }
  279. #pragma mark------用户名密码校验
  280. -(void)show{
  281. //这里校验有问题
  282. if (self.accountTF.text ==nil/*||self.accountTF.text.length<11||self.accountTF.text.length >11*/) {
  283. [self.loginButton setEnabled:NO];
  284. [self.registButton setEnabled:NO];
  285. ALERTSHOW(@"手机号不能为空");
  286. return;
  287. }
  288. if (self.passwordTF.text ==nil||self.passwordTF.text.length>8){
  289. [self.loginButton setEnabled:NO];
  290. [self.registButton setEnabled:NO];
  291. ALERTSHOW(@"密码输入有误");
  292. return;
  293. }
  294. if (![self.passwordTF.text isEqualToString:self.confirmPasswordTf.text]) {
  295. ALERTSHOW(@"两次输入密码不相同");
  296. return;
  297. }
  298. }
  299. #pragma mark - Delegate methods
  300. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  301. return YES;
  302. }
  303. //避免键盘遮挡,登录表单或按钮上移代码
  304. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  305. NSTimeInterval animationDuration = 0.30f;
  306. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  307. [UIView setAnimationDuration:animationDuration];
  308. //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
  309. self.view.frame = CGRectMake(0.0f, -50.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
  310. [UIView commitAnimations];
  311. return YES;
  312. }
  313. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  314. NSTimeInterval animationDuration = 0.30f;
  315. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  316. [UIView setAnimationDuration:animationDuration];
  317. //恢复屏幕
  318. self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
  319. [UIView commitAnimations];
  320. [[UIApplication sharedApplication].keyWindow endEditing:YES];
  321. }
  322. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  323. [textField resignFirstResponder];
  324. return YES;
  325. }
  326. - (void)didReceiveMemoryWarning {
  327. [super didReceiveMemoryWarning];
  328. // Dispose of any resources that can be recreated.
  329. }
  330. /*
  331. #pragma mark - Navigation
  332. // In a storyboard-based application, you will often want to do a little preparation before navigation
  333. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  334. // Get the new view controller using [segue destinationViewController].
  335. // Pass the selected object to the new view controller.
  336. }
  337. */
  338. @end