// // KXUserIdentificationContronller.m // QBCS // // Created by qianbodong on 2017/7/30. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXUserIdentificationContronller.h" #import #import #import @interface KXUserIdentificationContronller () @property (nonatomic,assign)NSUInteger tag; @property (nonatomic,strong)UIImagePickerController *picker; @property (nonatomic,assign)BOOL haveImageA; @property (nonatomic,assign)BOOL haveImageB; @end @implementation KXUserIdentificationContronller - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initNavBar]; [self initUIview]; } -(void)initNavBar { self.navigationController.navigationBar.hidden=NO; self.name=@"身份认证"; [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(beforeAction)]; } -(void)beforeAction { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"离开" message:@"现在离开将不会保存所填写信息,确认离开吗?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self.navigationController popViewControllerAnimated:YES]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)initUIview{ _tag=997; UIImageView *imageView=[[UIImageView alloc]init]; //WithFrame:CGRectMake(0, 44*SCREEN_MUTI, SCREEN_WIDTH, 130*SCREEN_MUTI)]; imageView.image=[UIImage imageNamed:@"main_identification_a"]; imageView.userInteractionEnabled = YES; UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)]; imageView.tag=997; [imageView addGestureRecognizer:singleTap]; [self.view addSubview:imageView]; [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).offset(44*SCREEN_MUTI); make.centerX.equalTo(self.view); make.size.mas_equalTo([imageView.image size]); }]; UIImageView *imageView1=[[UIImageView alloc]init]; imageView1.image=[UIImage imageNamed:@"main_identification_b"]; imageView1.userInteractionEnabled = YES; singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction1:)]; [imageView1 addGestureRecognizer:singleTap]; imageView1.tag=998; [self.view addSubview:imageView1]; [imageView1 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(imageView.mas_bottom).offset(32*SCREEN_MUTI); make.centerX.equalTo(self.view); make.size.mas_equalTo([imageView1.image size]); }]; UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom]; next.layer.cornerRadius=3; next.tag=999; next.layer.masksToBounds=YES; [next setBackgroundImage:[self imageWithColor:[UIColor baseColor]] forState:UIControlStateHighlighted |UIControlStateNormal]; [next setBackgroundImage:[self imageWithColor:[UIColor KXColorWithHex:0xd5d5d5]]forState:UIControlStateDisabled]; next.backgroundColor=[UIColor baseColor]; next.titleLabel.font=FONT_SYS(16); [next setTitle:@"提交" forState:UIControlStateNormal]; [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [next addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside]; next.enabled=NO; [self.view addSubview:next]; [next mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(imageView1.mas_bottom).offset(30*SCREEN_MUTI); make.left.equalTo(self.view.mas_left).offset(14*SCREEN_MUTI); make.right.equalTo(self.view.mas_right).offset(-14*SCREEN_MUTI); make.height.mas_equalTo(44*SCREEN_MUTI); }]; } -(UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } -(void)singleTapAction:(UIGestureRecognizer*) g { _tag=997; if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { [self presentViewController:self.picker animated:YES completion:nil]; } } -(void)singleTapAction1:(UIGestureRecognizer*) g { _tag=998; if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { [self presentViewController:self.picker animated:YES completion:nil]; } } #pragma mark UIImagePickerControllerDelegate //该代理方法仅适用于只选取图片时 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary *)editingInfo { if (image){ UIImageView* imageView=[self.view viewWithTag:_tag]; imageView.image = image; if(_tag==997){ _haveImageA=YES; if(_haveImageB){ UIButton* button=[self.view viewWithTag:999]; button.enabled=YES; } }else { _haveImageB=YES; if(_haveImageA){ UIButton* button=[self.view viewWithTag:999]; button.enabled=YES; } } } [self dismissViewControllerAnimated:YES completion:nil]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)submitAction:(UIButton*) button{ button.enabled=NO; [button setTitle:@"提交中..." forState:UIControlStateNormal]; NSString *urlS=[NSString stringWithFormat:@"%@/user/iosApply",URL]; // NSDictionary *paraDict=@{@"amount":@(_amount),@"term":@(_term),@"name":nameTF.text,@"age":ageTF.text,@"cell_num":cell_numTF.text,@"occupation":careerBtn.titleLabel.text,@"monthly_income":incomeBtn.titleLabel.text}; NSLog(@"%@",_paraDict); [KXHTTP post:urlS params:_paraDict success:^(id json) { // [[NSNotificationCenter defaultCenter]postNotificationName:KXWAITING object:nil userInfo:nil]; [self.navigationController popToRootViewControllerAnimated:YES]; } failure:^(NSError *error) { button.enabled=YES; }]; } -(UIImagePickerController*)picker{ if(!_picker){ self.picker= [[UIImagePickerController alloc] init]; _picker.delegate = self; // picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; _picker.allowsEditing = YES; _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } return _picker; } @end