SetPWDSecondViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // SetPWDSecondViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "SetPWDSecondViewController.h"
  8. #import <Masonry.h>
  9. @interface SetPWDSecondViewController (){
  10. NSString *pwd;
  11. UILabel *pointView0;
  12. UILabel *pointView1;
  13. UILabel *pointView2;
  14. UILabel *pointView3;
  15. UILabel *topLabel;
  16. }
  17. @end
  18. @implementation SetPWDSecondViewController
  19. @synthesize oldPWD;
  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. UIButton *upStepBtn = [[UIButton alloc] init];
  32. [upStepBtn setTitle:NSLocalizedString(@"guide_set_pwd_up_step",nil) forState:(UIControlStateNormal)];
  33. [upStepBtn setTitleColor:HW05BAFBColor forState:(UIControlStateNormal)];
  34. [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  35. [upStepBtn addTarget:self.navigationController
  36. action:@selector(popViewControllerAnimated:)
  37. forControlEvents:(UIControlEventTouchUpInside)];
  38. [self.view addSubview:upStepBtn];
  39. [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.mas_equalTo(10.f);
  41. make.width.mas_equalTo(58.f);
  42. make.top.mas_equalTo(5.f + H_STATE_BAR);
  43. make.height.mas_equalTo(32.f);
  44. }];
  45. /*设置密码标题*/
  46. topLabel = [[UILabel alloc] init];
  47. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  48. [topLabel setTextColor:HW333333Color];
  49. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  50. [topLabel setText:NSLocalizedString(@"guide_set_pwd_makesure_title",nil)];
  51. [self.view addSubview:topLabel];
  52. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(20);
  54. make.right.mas_equalTo(-20);
  55. make.top.mas_equalTo(99.f + H_STATE_BAR);
  56. }];
  57. CGFloat w_pwd = 24.f;
  58. CGFloat h_pwd = 24.f;
  59. CGFloat pointFont = 20.f;
  60. /*密码视图*/
  61. pointView0 = [[UILabel alloc] init];
  62. [pointView0 setTextColor:HW0A132BColor];
  63. [pointView0 setBackgroundColor:HWE3E8F1Color];
  64. [pointView0 setClipsToBounds:YES];
  65. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  66. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  67. [pointView0.layer setCornerRadius:w_pwd/2.f];
  68. [self.view addSubview:pointView0];
  69. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  71. make.height.mas_equalTo(h_pwd);
  72. make.width.mas_equalTo(w_pwd);
  73. make.top.mas_equalTo(151.f + H_STATE_BAR);
  74. }];
  75. pointView1 = [[UILabel alloc] init];
  76. [pointView1 setTextColor:HW0A132BColor];
  77. [pointView1 setBackgroundColor:HWE3E8F1Color];
  78. [pointView1 setClipsToBounds:YES];
  79. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  80. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  81. [pointView1.layer setCornerRadius:w_pwd/2.f];
  82. [self.view addSubview:pointView1];
  83. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  85. make.height.mas_equalTo(h_pwd);
  86. make.width.mas_equalTo(w_pwd);
  87. make.top.mas_equalTo(151.f + H_STATE_BAR);
  88. }];
  89. pointView2 = [[UILabel alloc] init];
  90. [pointView2 setTextColor:HW0A132BColor];
  91. [pointView2 setBackgroundColor:HWE3E8F1Color];
  92. [pointView2 setClipsToBounds:YES];
  93. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  94. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  95. [pointView2.layer setCornerRadius:w_pwd/2.f];
  96. [self.view addSubview:pointView2];
  97. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  99. make.height.mas_equalTo(h_pwd);
  100. make.width.mas_equalTo(w_pwd);
  101. make.top.mas_equalTo(151.f + H_STATE_BAR);
  102. }];
  103. pointView3 = [[UILabel alloc] init];
  104. [pointView3 setTextColor:HW0A132BColor];
  105. [pointView3 setBackgroundColor:HWE3E8F1Color];
  106. [pointView3 setClipsToBounds:YES];
  107. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  108. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  109. [pointView3.layer setCornerRadius:w_pwd/2.f];
  110. [self.view addSubview:pointView3];
  111. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  113. make.height.mas_equalTo(h_pwd);
  114. make.width.mas_equalTo(w_pwd);
  115. make.top.mas_equalTo(151.f + H_STATE_BAR);
  116. }];
  117. /*下方绘制键盘按钮*/
  118. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  119. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  120. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  121. CGFloat h_bgViewForNumberBoard = 330.f;
  122. [self.view addSubview:bgViewForNumberBoard];
  123. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.mas_equalTo(22.f*AUTOSCALE);
  125. make.height.mas_equalTo(h_bgViewForNumberBoard);
  126. make.width.mas_equalTo(w_bgViewForNumberBoard);
  127. make.bottom.mas_equalTo(-70.f);
  128. }];
  129. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  130. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  131. /*绘制键盘 1~9*/
  132. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  133. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  134. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  135. UIButton *keyBoardBtn = [[UIButton alloc] init];
  136. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  137. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  138. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  139. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  140. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  141. [bgViewForNumberBoard addSubview:keyBoardBtn];
  142. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.left.mas_equalTo(x_key_btn);
  144. make.top.mas_equalTo(y_key_btn);
  145. make.width.mas_equalTo(w_key_btn);
  146. make.height.mas_equalTo(h_key_btn);
  147. }];
  148. }
  149. /*删除按钮*/
  150. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  151. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  152. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  153. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  154. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  155. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.left.mas_equalTo(0);
  157. make.bottom.mas_equalTo(0);
  158. make.width.mas_equalTo(w_key_btn);
  159. make.height.mas_equalTo(h_key_btn);
  160. }];
  161. /*0*/
  162. UIButton *keyBoardBtn0 = [[UIButton alloc] init];
  163. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  164. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  165. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  166. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  167. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  168. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  169. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.left.mas_equalTo(w_key_btn);
  171. make.bottom.mas_equalTo(0);
  172. make.width.mas_equalTo(w_key_btn);
  173. make.height.mas_equalTo(h_key_btn);
  174. }];
  175. /*OK*/
  176. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  177. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  178. [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  179. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  180. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  181. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  182. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  183. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.left.mas_equalTo(2*w_key_btn);
  185. make.bottom.mas_equalTo(0);
  186. make.width.mas_equalTo(w_key_btn);
  187. make.height.mas_equalTo(h_key_btn);
  188. }];
  189. }
  190. - (void)deleteBoardBtnPressed{
  191. if (pwd.length > 0){
  192. NSInteger numberLength = pwd.length;
  193. if (numberLength == 1){
  194. [pointView0 setText:@""];
  195. [pointView0 setBackgroundColor:HWE3E8F1Color];
  196. }else if (numberLength == 2){
  197. [pointView1 setText:@""];
  198. [pointView1 setBackgroundColor:HWE3E8F1Color];
  199. }else if (numberLength == 3){
  200. [pointView2 setText:@""];
  201. [pointView2 setBackgroundColor:HWE3E8F1Color];
  202. }else if (numberLength == 4){
  203. [pointView3 setText:@""];
  204. [pointView3 setBackgroundColor:HWE3E8F1Color];
  205. }
  206. pwd = [pwd substringToIndex:numberLength-1];
  207. }
  208. }
  209. - (void)keyBoardBtnOKPressed{
  210. if (pwd.length == 4){
  211. if ([pwd isEqualToString:oldPWD]) {
  212. /*设置密码成功*/
  213. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  214. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  215. [dict setObject:pwd forKey:Const_Have_Add_Device_PWD];
  216. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  217. [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
  218. }else{
  219. /*提示密码不一致*/
  220. [topLabel setText:NSLocalizedString(@"guide_set_pwd_no_same",nil)];
  221. }
  222. }
  223. }
  224. - (void)keyBoardBtnPressed:(id)sender{
  225. UIButton *btn = (UIButton *)sender;
  226. NSString *selectNumberStr = btn.titleLabel.text;
  227. if (pwd.length < 4){
  228. NSInteger numberLength = pwd.length;
  229. if (numberLength == 0){
  230. [pointView0 setText:selectNumberStr];
  231. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  232. [self->pointView0 setBackgroundColor:HW0A132BColor];
  233. });
  234. }else if (numberLength == 1){
  235. [pointView1 setText:selectNumberStr];
  236. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  237. [self->pointView1 setBackgroundColor:HW0A132BColor];
  238. });
  239. }else if (numberLength == 2){
  240. [pointView2 setText:selectNumberStr];
  241. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  242. [self->pointView2 setBackgroundColor:HW0A132BColor];
  243. });
  244. }else if (numberLength == 3){
  245. [pointView3 setText:selectNumberStr];
  246. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  247. [self->pointView3 setBackgroundColor:HW0A132BColor];
  248. });
  249. }
  250. pwd = [pwd stringByAppendingString:selectNumberStr];
  251. }
  252. }
  253. /*
  254. #pragma mark - Navigation
  255. // In a storyboard-based application, you will often want to do a little preparation before navigation
  256. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  257. // Get the new view controller using [segue destinationViewController].
  258. // Pass the selected object to the new view controller.
  259. }
  260. */
  261. @end