Ei kuvausta

KXUserIdentificationContronller.m 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // KXUserIdentificationContronller.m
  3. // QBCS
  4. //
  5. // Created by qianbodong on 2017/7/30.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXUserIdentificationContronller.h"
  9. #import <MobileCoreServices/MobileCoreServices.h>
  10. #import <AVFoundation/AVFoundation.h>
  11. #import <MediaPlayer/MediaPlayer.h>
  12. @interface KXUserIdentificationContronller ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
  13. @property (nonatomic,assign)NSUInteger tag;
  14. @property (nonatomic,strong)UIImagePickerController *picker;
  15. @property (nonatomic,assign)BOOL haveImageA;
  16. @property (nonatomic,assign)BOOL haveImageB;
  17. @end
  18. @implementation KXUserIdentificationContronller
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self initNavBar];
  23. [self initUIview];
  24. }
  25. -(void)initNavBar
  26. {
  27. self.navigationController.navigationBar.hidden=NO;
  28. self.name=@"身份认证";
  29. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(beforeAction)];
  30. }
  31. -(void)beforeAction
  32. {
  33. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"离开" message:@"现在离开将不会保存所填写信息,确认离开吗?" preferredStyle:UIAlertControllerStyleAlert];
  34. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }]];
  37. [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  38. }]];
  39. [self presentViewController:alertController animated:YES completion:nil];
  40. }
  41. -(void)initUIview{
  42. _tag=997;
  43. UIImageView *imageView=[[UIImageView alloc]init];
  44. //WithFrame:CGRectMake(0, 44*SCREEN_MUTI, SCREEN_WIDTH, 130*SCREEN_MUTI)];
  45. imageView.image=[UIImage imageNamed:@"main_identification_a"];
  46. imageView.userInteractionEnabled = YES;
  47. UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)];
  48. imageView.tag=997;
  49. [imageView addGestureRecognizer:singleTap];
  50. [self.view addSubview:imageView];
  51. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.top.equalTo(self.view.mas_top).offset(44*SCREEN_MUTI);
  53. make.centerX.equalTo(self.view);
  54. make.size.mas_equalTo([imageView.image size]);
  55. }];
  56. UIImageView *imageView1=[[UIImageView alloc]init];
  57. imageView1.image=[UIImage imageNamed:@"main_identification_b"];
  58. imageView1.userInteractionEnabled = YES;
  59. singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction1:)];
  60. [imageView1 addGestureRecognizer:singleTap];
  61. imageView1.tag=998;
  62. [self.view addSubview:imageView1];
  63. [imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(imageView.mas_bottom).offset(32*SCREEN_MUTI);
  65. make.centerX.equalTo(self.view);
  66. make.size.mas_equalTo([imageView1.image size]);
  67. }];
  68. UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom];
  69. next.layer.cornerRadius=3;
  70. next.tag=999;
  71. next.layer.masksToBounds=YES;
  72. [next setBackgroundImage:[self imageWithColor:[UIColor baseColor]] forState:UIControlStateHighlighted |UIControlStateNormal];
  73. [next setBackgroundImage:[self imageWithColor:[UIColor KXColorWithHex:0xd5d5d5]]forState:UIControlStateDisabled];
  74. next.backgroundColor=[UIColor baseColor];
  75. next.titleLabel.font=FONT_SYS(16);
  76. [next setTitle:@"提交" forState:UIControlStateNormal];
  77. [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  78. [next addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
  79. next.enabled=NO;
  80. [self.view addSubview:next];
  81. [next mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(imageView1.mas_bottom).offset(30*SCREEN_MUTI);
  83. make.left.equalTo(self.view.mas_left).offset(14*SCREEN_MUTI);
  84. make.right.equalTo(self.view.mas_right).offset(-14*SCREEN_MUTI);
  85. make.height.mas_equalTo(44*SCREEN_MUTI);
  86. }];
  87. }
  88. -(UIImage *)imageWithColor:(UIColor *)color {
  89. CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
  90. UIGraphicsBeginImageContext(rect.size);
  91. CGContextRef context = UIGraphicsGetCurrentContext();
  92. CGContextSetFillColorWithColor(context, [color CGColor]);
  93. CGContextFillRect(context, rect);
  94. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  95. UIGraphicsEndImageContext();
  96. return image;
  97. }
  98. -(void)singleTapAction:(UIGestureRecognizer*) g
  99. {
  100. _tag=997;
  101. if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
  102. {
  103. [self presentViewController:self.picker animated:YES completion:nil];
  104. }
  105. }
  106. -(void)singleTapAction1:(UIGestureRecognizer*) g
  107. {
  108. _tag=998;
  109. if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
  110. {
  111. [self presentViewController:self.picker animated:YES completion:nil];
  112. }
  113. }
  114. #pragma mark UIImagePickerControllerDelegate
  115. //该代理方法仅适用于只选取图片时
  116. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo {
  117. if (image){
  118. UIImageView* imageView=[self.view viewWithTag:_tag];
  119. imageView.image = image;
  120. if(_tag==997){
  121. _haveImageA=YES;
  122. if(_haveImageB){
  123. UIButton* button=[self.view viewWithTag:999];
  124. button.enabled=YES;
  125. }
  126. }else {
  127. _haveImageB=YES;
  128. if(_haveImageA){
  129. UIButton* button=[self.view viewWithTag:999];
  130. button.enabled=YES;
  131. }
  132. }
  133. }
  134. [self dismissViewControllerAnimated:YES completion:nil];
  135. }
  136. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  137. {
  138. [self dismissViewControllerAnimated:YES completion:nil];
  139. }
  140. -(void)submitAction:(UIButton*) button{
  141. button.enabled=NO;
  142. [button setTitle:@"提交中..." forState:UIControlStateNormal];
  143. NSString *urlS=[NSString stringWithFormat:@"%@/user/iosApply",URL];
  144. // 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};
  145. NSLog(@"%@",_paraDict);
  146. [KXHTTP post:urlS params:_paraDict success:^(id json) {
  147. // [[NSNotificationCenter defaultCenter]postNotificationName:KXWAITING object:nil userInfo:nil];
  148. [self.navigationController popToRootViewControllerAnimated:YES];
  149. } failure:^(NSError *error) {
  150. button.enabled=YES;
  151. }];
  152. }
  153. -(UIImagePickerController*)picker{
  154. if(!_picker){
  155. self.picker= [[UIImagePickerController alloc] init];
  156. _picker.delegate = self;
  157. // picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  158. _picker.allowsEditing = YES;
  159. _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  160. }
  161. return _picker;
  162. }
  163. @end