// // FirstViewController.m // Talk // // Created by xuzs on 22/10/11. // Copyright (c) 2022年 xuzs. All rights reserved. // #import "FaceSubPage.h" #import #import "UI.h" #import "HttpManager.h" #import "Msg.h" #import "Pub.h" #import "sysInfo.h" #import "EquList.h" @interface FaceSubPage () @property (nonatomic, strong)UIView *rview; @end @implementation FaceSubPage - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self setupViews]; [self setUI]; } - (void)setupViews { [self.view addSubview:self.rview]; [self.rview addSubview:self.imgView]; [self.rview addSubview:self.hit]; [self.rview addSubview:self.button]; [self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Action)]]; } - (void)setUI{ [UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"]; NSLog(@"FaceSubPage:%f,%f",self.rview.frame.origin.x,self.rview.frame.size.width); [UI setFrameInView:self.imgView Width:@"86vw" Height:@"60vh" TranslateX:@"0" TranslateY:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]+20] InView:nil Position:UITopMid]; [UI setFrameByView:self.hit Width:@"86vw" Height:@"40" TranslateX:@"0" TranslateY:@"10" ByView:self.imgView Position:BottomAlignCenter]; [UI setFrameByView:self.button Width:@"86vw" Height:@"40" TranslateX:@"0" TranslateY:@"10" ByView:self.hit Position:BottomAlignCenter]; } - (void)Action{ NSLog(@"Action"); if(_no){ NSLog(@"删除"); [HttpManager delPhoto:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token No:_no HttpResultHandler:^(NSDictionary *json) { [self.parent ReLoad:0]; }]; } else{ NSLog(@"拍照"); if (![self isCameraAvailable]){[self alert:@"没有摄像头"];return;} if (![self doesCameraSupportTakingPhotos]){[self alert:@"不支持拍照"];return;} // 初始化图片选择控制器 UIImagePickerController *controller = [[UIImagePickerController alloc] init]; [controller setSourceType:UIImagePickerControllerSourceTypeCamera];// 设置类型 controller.cameraDevice = UIImagePickerControllerCameraDeviceFront;//默认前置摄像头 // 设置所支持的类型,设置只能拍照,或则只能录像,或者两者都可以 NSString *requiredMediaType = ( NSString *)kUTTypeImage; NSString *requiredMediaType1 = ( NSString *)kUTTypeMovie; //NSArray *arrMediaTypes=[NSArray arrayWithObjects:requiredMediaType, requiredMediaType1,nil]; NSArray *arrMediaTypes=[NSArray arrayWithObjects:requiredMediaType,nil]; [controller setMediaTypes:arrMediaTypes]; // 设置录制视频的质量 //[controller setVideoQuality:UIImagePickerControllerQualityTypeHigh]; //设置最长摄像时间 //[controller setVideoMaximumDuration:10.f]; //[controller setAllowsEditing:YES];// 设置是否可以管理已经存在的图片或者视频 [controller setDelegate:self];// 设置代理 [_parent.navigationController presentModalViewController:controller animated:YES]; //[controller release]; } } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSLog(@"didFinishPickingMediaWithInfo"); //NSLog(@"%@", info); NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; // 判断获取类型:图片 if ([mediaType isEqualToString:( NSString *)kUTTypeImage]){ UIImage *theImage = nil; // 判断,图片是否允许修改 if ([picker allowsEditing]){ //获取用户编辑之后的图像 theImage = [info objectForKey:UIImagePickerControllerEditedImage]; } else { // 照片的元数据参数 theImage = [info objectForKey:UIImagePickerControllerOriginalImage]; } [self.imgView setImage:theImage]; NSLog(@"UpPhoto"); self.hit.text = @"正在上传照片…"; [HttpManager UpPhoto:[Pub getApp].sysinfo.username Token:[Pub getApp].sysinfo.token Equid:_parent.equid Imgdata:UIImageJPEGRepresentation(theImage, .1) HttpResultHandler:^(NSDictionary *json) { if([[json objectForKey:@"result"] isEqualToString:@"ok"]){ NSLog(@"成功"); self.hit.text = @"上传成功"; [self.parent ReLoad:-2]; } else{ NSLog(@"失败"); self.hit.text = @"上传失败"; [self.parent alert:[json objectForKey:@"result"]]; } }]; } [picker dismissModalViewControllerAnimated:YES]; } // 判断设备是否有摄像头 - (BOOL)isCameraAvailable{ return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; } // 前面的摄像头是否可用 - (BOOL) isFrontCameraAvailable{ return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]; } // 后面的摄像头是否可用 - (BOOL) isRearCameraAvailable{ return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]; } // 判断是否支持某种多媒体类型:拍照,视频 - (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{ __block BOOL result = NO; if ([paramMediaType length] == 0){ NSLog(@"Media type is empty."); return NO; } NSArray *availableMediaTypes =[UIImagePickerController availableMediaTypesForSourceType:paramSourceType]; [availableMediaTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL*stop) { NSString *mediaType = (NSString *)obj; if ([mediaType isEqualToString:paramMediaType]){ result = YES; *stop= YES; } }]; return result; } // 检查摄像头是否支持录像 - (BOOL) doesCameraSupportShootingVideos{ return [self cameraSupportsMedia:( NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypeCamera]; } // 检查摄像头是否支持拍照 - (BOOL) doesCameraSupportTakingPhotos{ return [self cameraSupportsMedia:( NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark Property Accessors - (UIView *)rview { if (!_rview) { _rview = [[UIView alloc] init]; _rview.backgroundColor = [UIColor colorWithRed:189/255. green:211/255. blue:194/255. alpha:1]; } return _rview; } - (UILabel *)hit { if (!_hit) { _hit = [[UILabel alloc] init]; //_nameLabel.backgroundColor = [UIColor orangeColor]; //_nameLabel.numberOfLines = 0; _hit.font = [UIFont systemFontOfSize:15.0f]; _hit.textColor = [UIColor blackColor]; _hit.textAlignment = NSTextAlignmentCenter; _hit.text = NSLocalizedString(@"提示", nil); } return _hit; } - (UIImageView *)imgView { if (!_imgView) { _imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vcontacts2.png"]];//[UI reSizeImage: toSize:CGSizeMake(33, 33)]; _imgView.layer.opacity = .3; _imgView.contentMode = UIViewContentModeScaleAspectFit; } return _imgView; } - (UIButton *)button { if (!_button) { _button = [[UIButton alloc] init]; [_button setTitle:@"删除人脸信息" forState:UIControlStateNormal]; [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_button setTitleColor:[UIColor colorWithRed:255/255. green:128/255. blue:0/255. alpha:1] forState:UIControlStateHighlighted]; _button.backgroundColor = [UIColor redColor]; [_button.layer setMasksToBounds:YES]; [_button.layer setCornerRadius:5.0]; //设置矩形四个圆角半径 } return _button; } @end