SetPWDFirstViewController.m 15 KB

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