自定义身份证识别相机UI

来源:互联网 发布:keynote for mac 6.1 编辑:程序博客网 时间:2024/06/10 02:33

现在很多的项目都有身份证识别的环节,而系统的相机有时不能满足我们的需要,身份证的识别,有时需要对图片锐化,灰值,这时对于获取图片的尺寸 有为重要,网上很多厂商的SDK 都会把UI这个快 封装起来。我自定义一套希望对你们有用。

创建一个工程这里就不多说了 一样的套路

创建一个类

ImagePickerMamanger.h 

#import <Foundation/Foundation.h>@interface ImagePickerMamanger : NSObject+ (ImagePickerMamanger *)sharedInstance;#pragma mark - 照片/** *  @brief  从UIActionSheet中选择 * *  @param vc          presentVC *  @param block       成功回调 *  @param cancelBlock 取消回调 */- (void)cameraSheetInController:(UIViewController *)vc   sourceView:(UIView *)view handler:(void (^)(UIImage *image))block cancelHandler:(void (^)(void))cancelBlock;@end

ImagePickerMamanger.m

#define IS_IOS_8_OR_LATER [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0//屏幕宽#define IMAGEPICKER_SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width//屏幕高#define IMAGEPICKER_SCREEN_HEIGHT  [[UIScreen mainScreen] bounds].size.height#define  IMAGEPICKER_SIZE 300@interface ImagePickerMamanger()<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate>@property(nonatomic, strong) UIViewController *vc;@property(nonatomic, strong) UIImagePickerController *imagePickerController;@property(nonatomic,strong)UIPopoverController  * popoverController;@property(nonatomic, strong) void (^resultBlock)(UIImage *image);@property(nonatomic, strong) void (^cancelBlock)(void);@end@implementation ImagePickerMamangerstatic ImagePickerMamanger *sharedInstance = nil;#pragma mark Singleton Model+ (ImagePickerMamanger *)sharedInstance{    static dispatch_once_t onceToken;    dispatch_once(&onceToken, ^{        sharedInstance = [[ImagePickerMamanger alloc]init];        sharedInstance.imagePickerController = [[UIImagePickerController alloc]init];        sharedInstance.imagePickerController.delegate = sharedInstance;        if (IS_IOS_8_OR_LATER) {            sharedInstance.imagePickerController.modalPresentationStyle = UIModalPresentationOverFullScreen;        }    });    return sharedInstance;}#pragma mark - public methods- (void)cameraSheetInController:(UIViewController *)vc sourceView:(UIView *)view handler:(void (^)(UIImage *))block cancelHandler:(void (^)(void))cancelBlock{        self.vc = vc;        self.resultBlock = block;    self.cancelBlock = cancelBlock;        if (IS_IOS_8_OR_LATER) {        UIAlertController * alterController = [UIAlertController alertControllerWithTitle:@"选择图像" message:nil preferredStyle:UIAlertControllerStyleActionSheet];                // 判断是否支持相机        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){                        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {                                [alterController dismissViewControllerAnimated:YES completion:^(void){                    self.cancelBlock();                }];            }];                        UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {                [self openCamera:UIImagePickerControllerSourceTypeCamera];            }];                        UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {                [self openCamera:UIImagePickerControllerSourceTypePhotoLibrary];            }];                        [alterController addAction:deleteAction];            [alterController addAction:archiveAction];            [alterController addAction:cancelAction];                    }        else {                        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {                                [alterController dismissViewControllerAnimated:YES completion:^(void){                    self.cancelBlock();                }];            }];                        UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {                [self openCamera:UIImagePickerControllerSourceTypePhotoLibrary];            }];                        [alterController addAction:archiveAction];            [alterController addAction:cancelAction];                    }                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){            alterController.modalPresentationStyle = UIModalPresentationPopover;            alterController.popoverPresentationController.sourceView = view;                        alterController.popoverPresentationController.sourceRect = view.bounds;        }        [self.vc presentViewController:alterController animated:YES completion:nil];    }    else{        // 判断是否支持相机        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){                        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择",@"拍照", nil];            sheet.tag =100;            [sheet showInView:vc.view];        }else{            UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];            sheet.tag =101;            [sheet showInView:vc.view];        }    }}#pragma mark - UIImagePickerControllerDelegate- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{    // 照片    [picker dismissViewControllerAnimated:YES completion:^{}];        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];    self.resultBlock(image);    [self.vc setNeedsStatusBarAppearanceUpdate];};- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{    self.cancelBlock();    [self.vc setNeedsStatusBarAppearanceUpdate];    [self.vc dismissViewControllerAnimated:YES completion:^{    }];}-(void)imageWithPhotoInController:(UIViewController *)vc sourceView:(UIView *)view handler:(void (^)(UIImage *))block cancelHandler:(void (^)(void))cancelBlock{        self.vc = vc;    self.resultBlock = block;    self.cancelBlock = cancelBlock;        [self openCamera:UIImagePickerControllerSourceTypePhotoLibrary];}-(void)openCamera:(UIImagePickerControllerSourceType) souceType{    // 跳转到相机    self.imagePickerController.sourceType = souceType;        dispatch_async(dispatch_get_main_queue(), ^{                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {                        if (IS_IOS_8_OR_LATER) {                [self.vc presentViewController:self.imagePickerController animated:YES completion:^{}];            }else{                               UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:self.imagePickerController];                                self.popoverController = popover;                                [self.popoverController presentPopoverFromRect:CGRectMake((IMAGEPICKER_SCREEN_WIDTH - IMAGEPICKER_SIZE)/2, (IMAGEPICKER_SCREEN_HEIGHT - IMAGEPICKER_SIZE)/2, IMAGEPICKER_SIZE, IMAGEPICKER_SIZE) inView:self.vc.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];            }        }        else{            [self.vc presentViewController:self.imagePickerController animated:YES completion:^{}];        }        [self performSelector:@selector(delayHideStatusBar) withObject:nil afterDelay:0.5f];    });}-(void)delayHideStatusBar{    [self.vc setNeedsStatusBarAppearanceUpdate];}#pragma mark - UIActionSheetDelegate- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {       if (actionSheet.tag == 101) {        if (buttonIndex == 0) {            // 跳转到相机            [self openCamera:UIImagePickerControllerSourceTypePhotoLibrary];        }       else if (buttonIndex == 1) {            // 取消            [self.vc dismissViewControllerAnimated:YES completion:^{                self.cancelBlock();            }];        }    }else{        if (buttonIndex == 0) {            // 跳转到相机            [self openCamera:UIImagePickerControllerSourceTypePhotoLibrary];        }        else if (buttonIndex == 1) {                        // 跳转到相册页面            [self openCamera:UIImagePickerControllerSourceTypeCamera];        }       else if (buttonIndex == 2) {            // 取消           [self.vc dismissViewControllerAnimated:YES completion:^{               self.cancelBlock();            }];        }    }}@end
这个类用来管理相机的开启 拍摄成功后回调。



在建一个类 

CWPhotoController.h

#import <UIKit/UIKit.h>@protocol CWPhotoControllerDelegate <NSObject>- (void)cwAutoTakePhoto:(UIImage *)image;@end@interface CWPhotoGraphController : UIViewController@property(nonatomic,assign)BOOL   isFront;@property(nonatomic,assign)id<CWPhotoControllerDelegate> delegate;@end

CWPhotoGraphController.m

#import "CWPhotoGraphController.h"#import <AVFoundation/AVFoundation.h>@interface CWPhotoGraphController ()<AVCaptureMetadataOutputObjectsDelegate,UIAlertViewDelegate>{        UILabel   * label;        UIImageView * imageView;        CGRect     idCardRect;        UIImageView  * _focusView;}//捕获设备,通常是前置摄像头,后置摄像头,麦克风(音频输入)@property(nonatomic)AVCaptureDevice *device;//AVCaptureDeviceInput 代表输入设备,他使用AVCaptureDevice 来初始化@property(nonatomic)AVCaptureDeviceInput *input;//当启动摄像头开始捕获输入@property(nonatomic)AVCaptureMetadataOutput *output;@property (nonatomic)AVCaptureStillImageOutput *ImageOutPut;//session:由他把输入输出结合在一起,并开始启动捕获设备(摄像头)@property(nonatomic)AVCaptureSession *session;//图像预览层,实时显示捕获的图像@property(nonatomic)AVCaptureVideoPreviewLayer *previewLayer;@property (nonatomic)UIButton *flashButton;@property (nonatomic)BOOL isflashOn;@property(nonatomic,strong)UIImage * image;@end#define kScreenWidth  [UIScreen mainScreen].bounds.size.width#define kScreenHeight [UIScreen mainScreen].bounds.size.height#define HeadViewHight 40#define IDCardORigionY 30#define ClearBoxWidth (kScreenWidth- HeadViewHight - 20)#define ClearBoxHeight (kScreenHeight- IDCardORigionY - 100)#define photoButtonWidth 60@implementation CWPhotoGraphController#pragma mark#pragma mark----------- viewWillAppear viewWillAppear-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    if (self.navigationController != nil) {        self.navigationController.navigationBarHidden = YES;    }}#pragma mark#pragma mark----------- viewDidLoad viewDidLoad- (void)viewDidLoad {        [super viewDidLoad];        _focusView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 80)];    _focusView.backgroundColor = [UIColor clearColor];    _focusView.image = [UIImage imageNamed:@"focs"];    [self.view addSubview:_focusView];    _focusView.hidden = YES;    //_isFront = NO;    /**     *  @brief 相机权限     */    BOOL canOpenCamera = [self canUserCamear];        if (canOpenCamera) {        //自定义相机        [self customCamera];        //自定义相机显示View        [self custCameraView];    }else{        return;    }}#pragma mark#pragma mark ------------ canUserCamear 检查相机权限- (BOOL)canUserCamear{    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];        if (authStatus == AVAuthorizationStatusDenied) {                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"请打开相机权限" message:@"设置-隐私-相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];        alertView.tag = 100;        [alertView show];        return NO;    }    else{        return YES;    }    return YES;}#pragma mark#pragma mark ------------ clickedButtonAtIndex alterView代理方法/** *  @brief alterView代理方法 * *  @param alertView   alertView *  @param buttonIndex 按钮索引 */- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if (buttonIndex == 0 && alertView.tag == 100) {        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];                if([[UIApplication sharedApplication] canOpenURL:url]) {                        [[UIApplication sharedApplication] openURL:url];        }    }}#pragma mark#pragma mark----------- custCameraView 相机界面/** *  @brief 相机界面 */-(void)custCameraView{        /**     半透明背景     */    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];    [self.view addSubview:imageView];        imageView.backgroundColor = [UIColor clearColor];        imageView.userInteractionEnabled = YES;    /**     身份证对齐框     */    idCardRect = CGRectMake(HeadViewHight, IDCardORigionY, ClearBoxWidth, ClearBoxHeight);        if(IS_IPAD){        idCardRect = CGRectMake(100, 100, (kScreenWidth- 220), (kScreenHeight- 300));    }    /**     画中间透明周围半透明的图     */    UIImage * image = [self drawImage:imageView.frame AndClearRect:idCardRect];        imageView.image = image;        UIImageView * centerImageView = [[UIImageView alloc]initWithFrame:idCardRect];        centerImageView.backgroundColor = [UIColor clearColor];        centerImageView.userInteractionEnabled = YES;        //身份证正反面图    if (self.isFront) {        centerImageView.image = [UIImage imageNamed:@"frontBox"];    }else{        centerImageView.image = [UIImage imageNamed:@"backBox"];    }    [self.view addSubview:centerImageView];    /**     文字提示Label     */    if (IS_IPAD) {        label = [[UILabel alloc]initWithFrame:CGRectMake(-(kScreenWidth-80)/2, (kScreenHeight-100)/2, kScreenHeight-200, 40)];    }else{        if (kScreenHeight<568) {            label = [[UILabel alloc]initWithFrame:CGRectMake(-125, 220,kScreenHeight-200, 40)];        }else if(kScreenHeight == 667){            label = [[UILabel alloc]initWithFrame:CGRectMake(-210, 250, kScreenHeight-200, 40)];        }else if(kScreenHeight >= 736){            label = [[UILabel alloc]initWithFrame:CGRectMake(-245, 280, kScreenHeight-200, 40)];        }else{            label = [[UILabel alloc]initWithFrame:CGRectMake(-165, 230, kScreenHeight-200, 40)];        }    }        label.textAlignment = NSTextAlignmentCenter;    label.backgroundColor = [UIColor clearColor];    label.textColor = [UIColor whiteColor];    label.font =[UIFont boldSystemFontOfSize:17.f];    label.text = @"请横握手机拍照,并将身份证置于框内";    //顺时针旋转90度    label.transform = CGAffineTransformMakeRotation( M_PI/2 );    [self.view addSubview:label];    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(focusGesture:)];        [centerImageView addGestureRecognizer:tapGesture];        /**     *  @brief 拍照按钮     */    UIButton * photoButton = [UIButton buttonWithType:UIButtonTypeCustom];    photoButton.frame = CGRectMake((kScreenWidth-photoButtonWidth)/2+20, (kScreenHeight-photoButtonWidth-20), photoButtonWidth, photoButtonWidth);        [photoButton setImage:[UIImage imageNamed:@"paizhao1"] forState:UIControlStateNormal];        [self.view addSubview:photoButton];        [self.view bringSubviewToFront:photoButton];        [photoButton addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];        /**     *  @brief 返回按钮     */    UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];    backButton.frame = CGRectMake(20, (kScreenHeight-photoButtonWidth-20), 60, 60);    [backButton setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];    [self.view addSubview:backButton];    [backButton addTarget:self action:@selector(dismissViewController) forControlEvents:UIControlEventTouchUpInside];        self.flashButton = [UIButton buttonWithType:UIButtonTypeCustom];    self.flashButton.frame = CGRectMake(kScreenWidth-50, (kScreenHeight-photoButtonWidth-20), 30, 30);    [ self.flashButton setImage:[UIImage imageNamed:@"camera-flash-off"] forState:UIControlStateNormal];       [self.flashButton addTarget:self action:@selector(FlashOn) forControlEvents:UIControlEventTouchUpInside];     //[self.view addSubview:self.flashButton];        }- (void)focusGesture:(UITapGestureRecognizer*)gesture{    CGPoint point = [gesture locationInView:gesture.view];    [self focusAtPoint:point];}#pragma mark#pragma mark----------- customCamera 自定义相机/** *  @brief 自定义相机 */- (void)customCamera{        self.view.backgroundColor = [UIColor whiteColor];        //使用AVMediaTypeVideo 指明self.device代表视频,默认使用后置摄像头进行初始化    self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];        //使用设备初始化输入    self.input = [[AVCaptureDeviceInput alloc]initWithDevice:self.device error:nil];        //生成输出对象    self.output = [[AVCaptureMetadataOutput alloc]init];        self.ImageOutPut = [[AVCaptureStillImageOutput alloc] init];        NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];    self.ImageOutPut.outputSettings = outputSettings;    //生成会话,用来结合输入输出    self.session = [[AVCaptureSession alloc]init];    if ([self.session canSetSessionPreset:AVCaptureSessionPreset1280x720]) {        self.session.sessionPreset = AVCaptureSessionPreset1280x720;    }        if ([self.session canAddInput:self.input]) {        [self.session addInput:self.input];    }        if ([self.session canAddOutput:self.ImageOutPut]) {        [self.session addOutput:self.ImageOutPut];    }        //使用self.session,初始化预览层,self.session负责驱动input进行信息的采集,layer负责把图像渲染显示    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:self.session];        self.previewLayer.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);        self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;        [self.view.layer addSublayer:self.previewLayer];        //开始启动    [self.session startRunning];        if ([_device lockForConfiguration:nil]) {        if ([_device isFlashModeSupported:AVCaptureFlashModeAuto]) {            [_device setFlashMode:AVCaptureFlashModeAuto];        }        //自动白平衡        if ([_device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) {            [_device setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];        }        [_device unlockForConfiguration];    }       AVCaptureConnection  *  _videoConnection = [self.output connectionWithMediaType:AVMediaTypeVideo];    UIDeviceOrientation _camraOrientaion = [[UIDevice currentDevice] orientation];    if (_videoConnection.supportsVideoOrientation ) {        switch (_camraOrientaion) {            case UIDeviceOrientationPortrait:                _videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;                break;            case UIDeviceOrientationPortraitUpsideDown:                _videoConnection.videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;                break;            case UIDeviceOrientationLandscapeLeft:                _videoConnection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;                break;            case UIDeviceOrientationLandscapeRight:                _videoConnection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;                break;            default:                break;        }    }}#pragma mark#pragma mark----------- cameraWithPosition 获取相机设备/** *  @brief  获取相机 * *  @param position 相机类型、前置还是后置相机 * *  @return 相机device */- (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position{    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];    for ( AVCaptureDevice *device in devices )        if ( device.position == position ) return device;    return nil;}#pragma mark#pragma mark----------- FlashOn 打开或者关闭闪光灯/** *  @brief 打开或者关闭闪光灯 */- (void)FlashOn{        if ([_device lockForConfiguration:nil]) {        /**         *  @brief 关闭闪光灯         */        if (_isflashOn) {            if ([_device isFlashModeSupported:AVCaptureFlashModeOff]) {                [_device setFlashMode:AVCaptureFlashModeOff];                _isflashOn = NO;                [_flashButton setImage:[UIImage imageNamed:@"camera-flash-off"] forState:UIControlStateNormal];            }        }else{            /**             *  @brief 打开闪光灯             */            if ([_device isFlashModeSupported:AVCaptureFlashModeOn]) {                [_device setFlashMode:AVCaptureFlashModeOn];                _isflashOn = YES;                [_flashButton setImage:[UIImage imageNamed:@"camera-flash-on"] forState:UIControlStateNormal];            }        }        [_device unlockForConfiguration];    }}#pragma mark#pragma mark----------- focusAtPoint 相机对焦- (void)focusAtPoint:(CGPoint)point{    CGSize size = self.view.bounds.size;//    CGPoint point = CGPointMake(kScreenWidth/2, kScreenHeight/2);    CGPoint focusPoint = CGPointMake( point.y /size.height ,1-point.x/size.width );    NSError *error;    if ([self.device lockForConfiguration:&error]) {                if ([self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {            [self.device setFocusPointOfInterest:focusPoint];            [self.device setFocusMode:AVCaptureFocusModeAutoFocus];        }                if ([self.device isExposureModeSupported:AVCaptureExposureModeAutoExpose ]) {            [self.device setExposurePointOfInterest:focusPoint];            [self.device setExposureMode:AVCaptureExposureModeAutoExpose];        }                _focusView.center = point;                _focusView.hidden = NO;                [self.view bringSubviewToFront:_focusView];                [UIView animateWithDuration:0.3 animations:^{            _focusView.transform = CGAffineTransformMakeScale(1.1, 1.1);        }completion:^(BOOL finished) {            [UIView animateWithDuration:0.5 animations:^{                _focusView.transform = CGAffineTransformIdentity;            } completion:^(BOOL finished) {                _focusView.hidden = YES;            }];        }];        [self.device unlockForConfiguration];    }}#pragma mark#pragma mark--------------- takePhoto 拍摄照片- (void)takePhoto{    AVCaptureConnection * videoConnection = [self.ImageOutPut connectionWithMediaType:AVMediaTypeVideo];        if (!videoConnection) {        NSLog(@"take photo failed!");        return;    }    [self.ImageOutPut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {                if (imageDataSampleBuffer == NULL) {            return;        }        NSData * imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];                UIImage  * image = [UIImage imageWithData:imageData];        NSInteger card= [[CloudwalkFaceSDK shareInstance] cwIDCardInit:AuthCodeString];        
[self sendPhotoControllerDelegate:image];
}/** * @brief 拍照后的图片代理方法 * * @param idImage 拍摄的照片 */-(void)sendPhotoControllerDelegate:(UIImage *)idImage{ if (self.delegate != nil && [self.delegate respondsToSelector:@selector(cwAutoTakePhoto:)]) { [self.delegate cwAutoTakePhoto:idImage]; } dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewController]; });}#pragma mark#pragma mark----------- dismissViewController 关闭界面-(void)dismissViewController{ // [[CloudwalkFaceSDK shareInstance] cwDestroy]; //关闭相机界面 [self.session stopRunning]; if (self.navigationController != nil) { [self.navigationController popViewControllerAnimated:YES]; }else [self dismissViewControllerAnimated:YES completion:^{}];}#pragma mark#pragma mark-----------drawImage //画中间透明的图片-(UIImage *)drawImage:(CGRect)BgRect AndClearRect:(CGRect)ClearRect{ CGSize screenSize =[UIScreen mainScreen].bounds.size; UIGraphicsBeginImageContext(BgRect.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(ctx, 0,0,0,0.5); CGRect drawRect =CGRectMake(0, 0, screenSize.width,screenSize.height); CGContextFillRect(ctx, drawRect); CGContextClearRect(ctx, ClearRect); //clear the center rect of the layer UIImage* returnimage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return returnimage;}- (BOOL)prefersStatusBarHidden{ return YES;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#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

最后附上很类似的demo GitHub地址  https://github.com/wjx1018960145/Resource.git

 

原创粉丝点击