SetPWDFirstViewController.m 15 KB

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