SetPWDFirstViewController.m 16 KB

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