YOUPAILPYoungPwdVC.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // YOUPAILPYoungPwdVC.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/12/26.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPYoungPwdVC.h"
  9. #import "YOUPAIHWTFCursorView.h"
  10. @interface YOUPAILPYoungPwdVC ()<TFCodeViewDelegate,CAAnimationDelegate>
  11. @property(nonatomic,strong)YOUPAIHWTFCursorView *youpaipcodeView;
  12. @property(nonatomic,strong)NSString *youpaiptitleStr;
  13. @property(nonatomic,strong)UILabel *youpaiptitleLab;
  14. @end
  15. @implementation YOUPAILPYoungPwdVC
  16. -(void)viewWillAppear:(BOOL)animated
  17. {
  18. [super viewWillAppear:animated];
  19. [self.youpaipcodeView.textField becomeFirstResponder];
  20. self.youpaipcodeView.textField.secureTextEntry = YES;
  21. }
  22. -(void)viewWillDisappear:(BOOL)animated
  23. {
  24. [super viewWillDisappear:animated];
  25. // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
  26. // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
  27. // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
  28. // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. if(_youpaippwdStatus == TFPWDSETTING)
  33. {
  34. self.youpaiptitleStr = @"设置密码";
  35. }
  36. else if(_youpaippwdStatus == TFPWDCONFIRM)
  37. {
  38. self.youpaiptitleStr = @"确认密码";
  39. }
  40. else if(_youpaippwdStatus == TFPWDCLOSE)
  41. {
  42. self.youpaiptitleStr = @"输入密码";
  43. }
  44. self.title = @"青少年模式";
  45. [self.view setBackgroundColor:[UIColor whiteColor]];
  46. [self youpaifsetCodeView];
  47. // Do any additional setup after loading the view.
  48. }
  49. -(void)youpaifsetCodeView
  50. {
  51. // CGFloat x = 30;
  52. // CGFloat w = KScreenWidth - x * 2;
  53. // CGFloat h = 50;
  54. // CGFloat y = 100;
  55. _youpaiptitleLab = [UILabel new];
  56. [_youpaiptitleLab setTextAlignment:NSTextAlignmentCenter];
  57. _youpaiptitleLab.textColor = LZ273145Color;
  58. _youpaiptitleLab.font = LCBoldFont(27.0f);
  59. _youpaiptitleLab.text = self.youpaiptitleStr;
  60. // _youpaiptitleLab.frame = CGRectMake(x, y, KScreenWidth-60, 20);
  61. [self.view addSubview:self.youpaiptitleLab];
  62. [self.youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.offset(27.0f);
  64. make.top.offset(40.0f + NavBarHeight);
  65. }];
  66. YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:7 haveBorder:YES];
  67. codeView.frame = CGRectMake(27, 107 + NavBarHeight, KScreenWidth-54, 56);
  68. [codeView setBackgroundColor:[UIColor clearColor]];
  69. [self.view addSubview:codeView];
  70. codeView.delegate =self;
  71. self.youpaipcodeView = codeView;
  72. // YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:20 haveBorder:NO];
  73. // codeView.frame = CGRectMake(x, y+30, w, h);
  74. // [codeView setBackgroundColor:[UIColor clearColor]];
  75. // [self.view addSubview:codeView];
  76. // codeView.delegate =self;
  77. // self.youpaipcodeView = codeView;
  78. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftap)];
  79. [self.view addGestureRecognizer:tap];
  80. }
  81. - (void)youpaiftap
  82. {
  83. [self.youpaipcodeView endEditing:YES];
  84. }
  85. -(void)youpaifinputFinished:(NSString *)inputStr
  86. {
  87. if(_youpaippwdStatus == TFPWDCLOSE)
  88. {
  89. [self youpaifswitchAdenscent:inputStr opened:0];
  90. }
  91. else if(_youpaippwdStatus == TFPWDCONFIRM)
  92. {
  93. if([self.youpaipinputPwd isEqualToString:inputStr])
  94. {
  95. //开启青少年模式 改为设置密码
  96. // [self youpaifswitchAdenscent:inputStr opened:1];
  97. [self youpaifsetYoungPwd:inputStr];
  98. }
  99. else
  100. {
  101. CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
  102. CGFloat currentTx = _youpaipcodeView.transform.tx;
  103. animation.delegate = self;
  104. animation.duration = 1;
  105. animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
  106. animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
  107. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  108. animation.repeatCount = 1;
  109. [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
  110. }
  111. }
  112. else if(_youpaippwdStatus == TFPWDSETTING)
  113. {
  114. YOUPAILPYoungPwdVC *confirmVc = [[YOUPAILPYoungPwdVC alloc]init];
  115. confirmVc.youpaipdelegate = self.youpaipdelegate;
  116. confirmVc.youpaippwdStatus = TFPWDCONFIRM;
  117. confirmVc.youpaipinputPwd = inputStr;
  118. [self.navigationController pushViewController:confirmVc animated:YES];
  119. }
  120. }
  121. //关闭青少年模式
  122. -(void)youpaifswitchAdenscent:(NSString *)password opened:(NSInteger)opened
  123. {
  124. [LCHttpHelper requestWithURLString:SwitchAdolescent parameters:@{@"is_open":@(opened),@"password":password} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  125. NSDictionary* dict = (NSDictionary*)responseObject;
  126. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  127. if (code==0) {//成功
  128. // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
  129. // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
  130. // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
  131. // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  132. if(opened==1)
  133. {
  134. //开启
  135. [_youpaipdelegate youpaifswitchYounModel:1];
  136. }
  137. else
  138. {
  139. [_youpaipdelegate youpaifswitchYounModel:0];
  140. }
  141. [self.navigationController popToRootViewControllerAnimated:YES];
  142. }
  143. else
  144. {
  145. CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
  146. CGFloat currentTx = _youpaipcodeView.transform.tx;
  147. animation.delegate = self;
  148. animation.duration = 1;
  149. animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
  150. animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
  151. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  152. [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
  153. }
  154. // [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
  155. } failure:^(NSError *error) {
  156. [ZCHUDHelper showTitle:error.mj_JSONString showtime:1];
  157. [self dismissViewControllerAnimated:YES completion:nil];
  158. }];
  159. }
  160. -(void)youpaifsetYoungPwd:(NSString *)password
  161. {
  162. [LCHttpHelper requestWithURLString:SetAdolescent parameters:@{@"password":password} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  163. NSDictionary* dict = (NSDictionary*)responseObject;
  164. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  165. if (code==0) {//成功
  166. // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
  167. // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
  168. // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
  169. // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  170. [self.navigationController popToRootViewControllerAnimated:YES];
  171. [_youpaipdelegate youpaifswitchYounModel:1];
  172. }
  173. else
  174. {
  175. CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
  176. CGFloat currentTx = _youpaipcodeView.transform.tx;
  177. animation.delegate = self;
  178. animation.duration = 1;
  179. animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
  180. animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
  181. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  182. [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
  183. }
  184. // [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
  185. } failure:^(NSError *error) {
  186. [ZCHUDHelper showTitle:error.mj_JSONString showtime:1];
  187. [self dismissViewControllerAnimated:YES completion:nil];
  188. }];
  189. }
  190. -(void)back
  191. {
  192. [self.navigationController popViewControllerAnimated:YES];
  193. }
  194. /*
  195. #pragma mark - Navigation
  196. // In a storyboard-based application, you will often want to do a little preparation before navigation
  197. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  198. // Get the new view controller using [segue destinationViewController].
  199. // Pass the selected object to the new view controller.
  200. }
  201. */
  202. @end