SetPWDFirstViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //
  2. // SetPWDFirstViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "SetPWDFirstViewController.h"
  8. #import <Masonry.h>
  9. #import "SetPWDSecondViewController.h"
  10. @interface SetPWDFirstViewController (){
  11. NSString *pwd;
  12. UILabel *pointView0;
  13. UILabel *pointView1;
  14. UILabel *pointView2;
  15. UILabel *pointView3;
  16. UIButton *keyBoardBtn0;
  17. }
  18. @end
  19. @implementation SetPWDFirstViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. pwd = @"";
  24. [self drawAnyView];
  25. //发个通知 记录进入了设置密码
  26. if(!_isForgetPwdType){
  27. [[NSNotificationCenter defaultCenter] postNotificationName:setPwdNotification object:nil];
  28. }
  29. }
  30. - (void)drawAnyView{
  31. [self.navigationBar setHidden:YES];
  32. [self.toolBar setHidden:YES];
  33. [self.view setBackgroundColor:HWF5F7FAColor];
  34. /*设置密码标题*/
  35. UILabel *topLabel = [[UILabel alloc] init];
  36. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  37. [topLabel setTextColor:HW333333Color];
  38. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  39. [topLabel setText:NSLocalizedString(@"guide_set_pwd_title",nil)];
  40. [self.view addSubview:topLabel];
  41. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(20);
  43. make.right.mas_equalTo(-20);
  44. make.top.mas_equalTo(99.f + H_STATE_BAR);
  45. }];
  46. CGFloat w_pwd = 24.f;
  47. CGFloat h_pwd = 24.f;
  48. CGFloat pointFont = 20.f;
  49. /*密码视图*/
  50. pointView0 = [[UILabel alloc] init];
  51. [pointView0 setTextColor:HW0A132BColor];
  52. [pointView0 setBackgroundColor:HWE3E8F1Color];
  53. [pointView0 setClipsToBounds:YES];
  54. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  55. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  56. [pointView0.layer setCornerRadius:w_pwd/2.f];
  57. [self.view addSubview:pointView0];
  58. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  60. make.height.mas_equalTo(h_pwd);
  61. make.width.mas_equalTo(w_pwd);
  62. make.top.mas_equalTo(151.f + H_STATE_BAR);
  63. }];
  64. pointView1 = [[UILabel alloc] init];
  65. [pointView1 setTextColor:HW0A132BColor];
  66. [pointView1 setBackgroundColor:HWE3E8F1Color];
  67. [pointView1 setClipsToBounds:YES];
  68. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  69. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  70. [pointView1.layer setCornerRadius:w_pwd/2.f];
  71. [self.view addSubview:pointView1];
  72. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  74. make.height.mas_equalTo(h_pwd);
  75. make.width.mas_equalTo(w_pwd);
  76. make.top.mas_equalTo(151.f + H_STATE_BAR);
  77. }];
  78. pointView2 = [[UILabel alloc] init];
  79. [pointView2 setTextColor:HW0A132BColor];
  80. [pointView2 setBackgroundColor:HWE3E8F1Color];
  81. [pointView2 setClipsToBounds:YES];
  82. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  83. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  84. [pointView2.layer setCornerRadius:w_pwd/2.f];
  85. [self.view addSubview:pointView2];
  86. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  88. make.height.mas_equalTo(h_pwd);
  89. make.width.mas_equalTo(w_pwd);
  90. make.top.mas_equalTo(151.f + H_STATE_BAR);
  91. }];
  92. pointView3 = [[UILabel alloc] init];
  93. [pointView3 setTextColor:HW0A132BColor];
  94. [pointView3 setBackgroundColor:HWE3E8F1Color];
  95. [pointView3 setClipsToBounds:YES];
  96. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  97. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  98. [pointView3.layer setCornerRadius:w_pwd/2.f];
  99. [self.view addSubview:pointView3];
  100. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  102. make.height.mas_equalTo(h_pwd);
  103. make.width.mas_equalTo(w_pwd);
  104. make.top.mas_equalTo(151.f + H_STATE_BAR);
  105. }];
  106. /*下方绘制键盘按钮*/
  107. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  108. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  109. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  110. CGFloat h_bgViewForNumberBoard = 330.f;
  111. [self.view addSubview:bgViewForNumberBoard];
  112. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.mas_equalTo(22.f*AUTOSCALE);
  114. make.height.mas_equalTo(h_bgViewForNumberBoard);
  115. make.width.mas_equalTo(w_bgViewForNumberBoard);
  116. make.bottom.mas_equalTo(-70.f);
  117. }];
  118. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  119. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  120. /*绘制键盘 1~9*/
  121. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  122. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  123. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  124. UIButton *keyBoardBtn = [[UIButton alloc] init];
  125. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  126. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  127. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  128. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  129. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  130. [bgViewForNumberBoard addSubview:keyBoardBtn];
  131. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.left.mas_equalTo(x_key_btn);
  133. make.top.mas_equalTo(y_key_btn);
  134. make.width.mas_equalTo(w_key_btn);
  135. make.height.mas_equalTo(h_key_btn);
  136. }];
  137. }
  138. /*删除按钮*/
  139. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  140. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  141. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  142. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  143. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  144. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.left.mas_equalTo(0);
  146. make.bottom.mas_equalTo(0);
  147. make.width.mas_equalTo(w_key_btn);
  148. make.height.mas_equalTo(h_key_btn);
  149. }];
  150. /*0*/
  151. keyBoardBtn0 = [[UIButton alloc] init];
  152. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  153. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  154. [keyBoardBtn0 setTitleColor:COLOR_PACEHOLDER forState:(UIControlStateDisabled)];
  155. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  156. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  157. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  158. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  159. keyBoardBtn0.enabled = NO;
  160. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.left.mas_equalTo(w_key_btn);
  162. make.bottom.mas_equalTo(0);
  163. make.width.mas_equalTo(w_key_btn);
  164. make.height.mas_equalTo(h_key_btn);
  165. }];
  166. /*OK*/
  167. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  168. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  169. [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  170. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  171. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  172. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  173. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  174. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  175. make.left.mas_equalTo(2*w_key_btn);
  176. make.bottom.mas_equalTo(0);
  177. make.width.mas_equalTo(w_key_btn);
  178. make.height.mas_equalTo(h_key_btn);
  179. }];
  180. /*绘制引导视图*/
  181. [self addGuideView];
  182. }
  183. - (void)addGuideView{
  184. UIView *bgView = [[UIView alloc] init];
  185. [bgView setBackgroundColor:HW000000Color60];
  186. [self.view addSubview:bgView];
  187. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  188. make.left.mas_equalTo(0);
  189. make.bottom.mas_equalTo(0);
  190. make.right.mas_equalTo(0);
  191. make.top.mas_equalTo(0);
  192. }];
  193. /*密码背景*/
  194. UIView *pwdBgView = [[UIView alloc] init];
  195. [pwdBgView setBackgroundColor:HWF5F7FAColor];
  196. pwdBgView.layer.cornerRadius = 26.f;
  197. [bgView addSubview:pwdBgView];
  198. [pwdBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  199. make.centerX.equalTo(bgView.mas_centerX);
  200. make.top.mas_equalTo(68.f + H_STATE_BAR);
  201. make.width.mas_equalTo(248);
  202. make.height.mas_equalTo(138);
  203. }];
  204. /*密码*/
  205. UILabel *topLabel = [[UILabel alloc] init];
  206. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  207. [topLabel setTextColor:HW333333Color];
  208. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  209. [topLabel setText:NSLocalizedString(@"guide_set_pwd_title",nil)];
  210. [pwdBgView addSubview:topLabel];
  211. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  212. make.left.mas_equalTo(20);
  213. make.right.mas_equalTo(-20);
  214. make.top.mas_equalTo(31.f);
  215. }];
  216. for (NSInteger nfori = 0; nfori < 4; nfori++) {
  217. CGFloat w_pwd = 24.f;
  218. CGFloat h_pwd = 24.f;
  219. /*密码视图*/
  220. UILabel *pointView = [[UILabel alloc] init];
  221. [pointView setBackgroundColor:HWE3E8F1Color];
  222. [pointView setClipsToBounds:YES];
  223. [pointView.layer setCornerRadius:w_pwd/2.f];
  224. [pwdBgView addSubview:pointView];
  225. [pointView mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.left.mas_equalTo(40.f + (w_pwd + w_pwd)*nfori);
  227. make.height.mas_equalTo(h_pwd);
  228. make.width.mas_equalTo(w_pwd);
  229. make.top.mas_equalTo(83.f);
  230. }];
  231. }
  232. /*箭头视图*/
  233. UIImageView *flagImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_set_pwd_flag"]];
  234. [bgView addSubview:flagImageView];
  235. [flagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  236. make.left.equalTo(pwdBgView.mas_left).offset(49);
  237. make.height.mas_equalTo(56);
  238. make.width.mas_equalTo(14);
  239. make.top.equalTo(pwdBgView.mas_bottom);
  240. }];
  241. /*不可点击btn*/
  242. UIButton *unableBtn = [[UIButton alloc] init];
  243. unableBtn.frame = CGRectMake(0, 0, 250, 40.f);
  244. // gradient
  245. CAGradientLayer *gl = [CAGradientLayer layer];
  246. gl.frame = CGRectMake(0,0,250,40.f);
  247. gl.startPoint = CGPointMake(0, 0.5);
  248. gl.endPoint = CGPointMake(1, 0.5);
  249. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  250. gl.locations = @[@(0), @(1.0f)];
  251. [unableBtn.layer addSublayer:gl];
  252. [unableBtn setUserInteractionEnabled:NO];
  253. [unableBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide",nil) forState:(UIControlStateNormal)];
  254. [unableBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  255. [unableBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  256. [unableBtn.layer setCornerRadius:8.f];
  257. unableBtn.clipsToBounds = YES;
  258. [bgView addSubview:unableBtn];
  259. [unableBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  260. make.left.equalTo(pwdBgView.mas_left).offset(16);
  261. make.width.mas_equalTo(250);
  262. make.top.equalTo(flagImageView.mas_bottom);
  263. make.height.mas_equalTo(40.f);
  264. }];
  265. UIButton *knowBtn = [[UIButton alloc] init];
  266. [knowBtn setBackgroundColor:[UIColor clearColor]];
  267. [knowBtn.layer setCornerRadius:18.f];
  268. [knowBtn.layer setBorderColor:HWFFFFFFColor.CGColor];
  269. [knowBtn.layer setBorderWidth:1];
  270. [knowBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:(UIControlStateNormal)];
  271. [knowBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  272. [knowBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  273. [bgView addSubview:knowBtn];
  274. [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  275. make.right.equalTo(pwdBgView.mas_right).offset(-10);
  276. make.width.mas_equalTo(120);
  277. make.top.equalTo(unableBtn.mas_bottom).offset(25);
  278. make.height.mas_equalTo(36.f);
  279. }];
  280. [knowBtn addTarget:bgView
  281. action:@selector(removeFromSuperview)
  282. forControlEvents:(UIControlEventTouchUpInside)];
  283. }
  284. - (void)deleteBoardBtnPressed{
  285. if (pwd.length > 0){
  286. NSInteger numberLength = pwd.length;
  287. if (numberLength == 1){
  288. [pointView0 setText:@""];
  289. [pointView0 setBackgroundColor:HWE3E8F1Color];
  290. }else if (numberLength == 2){
  291. [pointView1 setText:@""];
  292. [pointView1 setBackgroundColor:HWE3E8F1Color];
  293. }else if (numberLength == 3){
  294. [pointView2 setText:@""];
  295. [pointView2 setBackgroundColor:HWE3E8F1Color];
  296. }else if (numberLength == 4){
  297. [pointView3 setText:@""];
  298. [pointView3 setBackgroundColor:HWE3E8F1Color];
  299. }
  300. pwd = [pwd substringToIndex:numberLength-1];
  301. }
  302. }
  303. - (void)keyBoardBtnOKPressed{
  304. if (pwd.length == 4){
  305. /*进入下一级确认密码*/
  306. SetPWDSecondViewController *nextVC = [[SetPWDSecondViewController alloc] init];
  307. nextVC.oldPWD = pwd;
  308. nextVC.isForgetPwdType = _isForgetPwdType;
  309. [self.navigationController pushViewController:nextVC animated:YES];
  310. if(!_isForgetPwdType){
  311. [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:YES];
  312. }
  313. }
  314. }
  315. - (void)keyBoardBtnPressed:(id)sender{
  316. UIButton *btn = (UIButton *)sender;
  317. NSString *selectNumberStr = btn.titleLabel.text;
  318. if (pwd.length < 4){
  319. NSInteger numberLength = pwd.length;
  320. if (numberLength == 0){
  321. [pointView0 setText:selectNumberStr];
  322. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  323. [self->pointView0 setBackgroundColor:HW0A132BColor];
  324. self->keyBoardBtn0.enabled = YES;
  325. });
  326. }else if (numberLength == 1){
  327. [pointView1 setText:selectNumberStr];
  328. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  329. [self->pointView1 setBackgroundColor:HW0A132BColor];
  330. });
  331. }else if (numberLength == 2){
  332. [pointView2 setText:selectNumberStr];
  333. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  334. [self->pointView2 setBackgroundColor:HW0A132BColor];
  335. });
  336. }else if (numberLength == 3){
  337. [pointView3 setText:selectNumberStr];
  338. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  339. [self->pointView3 setBackgroundColor:HW0A132BColor];
  340. });
  341. }
  342. pwd = [pwd stringByAppendingString:selectNumberStr];
  343. }
  344. }
  345. /*
  346. #pragma mark - Navigation
  347. // In a storyboard-based application, you will often want to do a little preparation before navigation
  348. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  349. // Get the new view controller using [segue destinationViewController].
  350. // Pass the selected object to the new view controller.
  351. }
  352. */
  353. @end