123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //
- // YOUPAILPYoungPwdVC.m
- // livePro
- //
- // Created by leo on 2019/12/26.
- // Copyright © 2019 caiPro. All rights reserved.
- //
- #import "YOUPAILPYoungPwdVC.h"
- #import "YOUPAIHWTFCursorView.h"
- @interface YOUPAILPYoungPwdVC ()<TFCodeViewDelegate,CAAnimationDelegate>
- @property(nonatomic,strong)YOUPAIHWTFCursorView *youpaipcodeView;
- @property(nonatomic,strong)NSString *youpaiptitleStr;
- @property(nonatomic,strong)UILabel *youpaiptitleLab;
- @end
- @implementation YOUPAILPYoungPwdVC
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.youpaipcodeView.textField becomeFirstResponder];
- self.youpaipcodeView.textField.secureTextEntry = YES;
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
- // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
- // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
- // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- if(_youpaippwdStatus == TFPWDSETTING)
- {
- self.youpaiptitleStr = @"设置密码";
- }
- else if(_youpaippwdStatus == TFPWDCONFIRM)
- {
- self.youpaiptitleStr = @"确认密码";
- }
- else if(_youpaippwdStatus == TFPWDCLOSE)
- {
- self.youpaiptitleStr = @"输入密码";
- }
- self.title = @"青少年模式";
- [self.view setBackgroundColor:[UIColor whiteColor]];
- [self youpaifsetCodeView];
- // Do any additional setup after loading the view.
- }
- -(void)youpaifsetCodeView
- {
- // CGFloat x = 30;
- // CGFloat w = KScreenWidth - x * 2;
- // CGFloat h = 50;
- // CGFloat y = 100;
-
- _youpaiptitleLab = [UILabel new];
- [_youpaiptitleLab setTextAlignment:NSTextAlignmentCenter];
- _youpaiptitleLab.textColor = LZ273145Color;
- _youpaiptitleLab.font = LCBoldFont(27.0f);
- _youpaiptitleLab.text = self.youpaiptitleStr;
- // _youpaiptitleLab.frame = CGRectMake(x, y, KScreenWidth-60, 20);
- [self.view addSubview:self.youpaiptitleLab];
- [self.youpaiptitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(27.0f);
- make.top.offset(40.0f + NavBarHeight);
- }];
-
-
- YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:7 haveBorder:YES];
- codeView.frame = CGRectMake(27, 107 + NavBarHeight, KScreenWidth-54, 56);
- [codeView setBackgroundColor:[UIColor clearColor]];
- [self.view addSubview:codeView];
- codeView.delegate =self;
- self.youpaipcodeView = codeView;
-
- // YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:20 haveBorder:NO];
- // codeView.frame = CGRectMake(x, y+30, w, h);
- // [codeView setBackgroundColor:[UIColor clearColor]];
- // [self.view addSubview:codeView];
- // codeView.delegate =self;
- // self.youpaipcodeView = codeView;
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftap)];
- [self.view addGestureRecognizer:tap];
-
- }
- - (void)youpaiftap
- {
- [self.youpaipcodeView endEditing:YES];
- }
- -(void)youpaifinputFinished:(NSString *)inputStr
- {
- if(_youpaippwdStatus == TFPWDCLOSE)
- {
- [self youpaifswitchAdenscent:inputStr opened:0];
- }
- else if(_youpaippwdStatus == TFPWDCONFIRM)
- {
- if([self.youpaipinputPwd isEqualToString:inputStr])
- {
- //开启青少年模式 改为设置密码
- // [self youpaifswitchAdenscent:inputStr opened:1];
- [self youpaifsetYoungPwd:inputStr];
- }
- else
- {
- CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
- CGFloat currentTx = _youpaipcodeView.transform.tx;
-
- animation.delegate = self;
- animation.duration = 1;
- animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
- animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- animation.repeatCount = 1;
- [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
- }
- }
- else if(_youpaippwdStatus == TFPWDSETTING)
- {
- YOUPAILPYoungPwdVC *confirmVc = [[YOUPAILPYoungPwdVC alloc]init];
- confirmVc.youpaipdelegate = self.youpaipdelegate;
- confirmVc.youpaippwdStatus = TFPWDCONFIRM;
- confirmVc.youpaipinputPwd = inputStr;
- [self.navigationController pushViewController:confirmVc animated:YES];
- }
- }
- //关闭青少年模式
- -(void)youpaifswitchAdenscent:(NSString *)password opened:(NSInteger)opened
- {
- [LCHttpHelper requestWithURLString:SwitchAdolescent parameters:@{@"is_open":@(opened),@"password":password} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
- // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
- // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
- // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
- if(opened==1)
- {
- //开启
- [_youpaipdelegate youpaifswitchYounModel:1];
- }
- else
- {
- [_youpaipdelegate youpaifswitchYounModel:0];
- }
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- else
- {
- CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
- CGFloat currentTx = _youpaipcodeView.transform.tx;
-
- animation.delegate = self;
- animation.duration = 1;
- animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
- animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
- }
- // [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.mj_JSONString showtime:1];
- [self dismissViewControllerAnimated:YES completion:nil];
- }];
- }
- -(void)youpaifsetYoungPwd:(NSString *)password
- {
- [LCHttpHelper requestWithURLString:SetAdolescent parameters:@{@"password":password} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- // self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:[UIImage imageNamed:@"nav_back_normal"]];
- // [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
- // [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
- // self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
- [self.navigationController popToRootViewControllerAnimated:YES];
- [_youpaipdelegate youpaifswitchYounModel:1];
- }
- else
- {
- CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
- CGFloat currentTx = _youpaipcodeView.transform.tx;
-
- animation.delegate = self;
- animation.duration = 1;
- animation.values = @[ @(currentTx), @(currentTx + 10), @(currentTx-8), @(currentTx + 8), @(currentTx -5), @(currentTx + 5), @(currentTx) ];
- animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- [_youpaipcodeView.layer addAnimation:animation forKey:@"ShakerAnimationKey"];
- }
- // [ZCHUDHelper showTitle:dict[@"message"] showtime:1];
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.mj_JSONString showtime:1];
- [self dismissViewControllerAnimated:YES completion:nil];
- }];
- }
- -(void)back
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|