SetPWDFirstViewController.m 15 KB

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