UserRegister_VC.m 17 KB

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