//
// ScanCameraController.m
// FanHeIOS2.0
//
// Created by 胡梦驰 on 2017/8/14.
// Copyright © 2017年 胡梦驰. All rights reserved.
//
#import "ScanCameraController.h"
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "ScanCardViewController.h"
typedef void(^PropertyChangeBlock)(AVCaptureDevice *captureDevice);
@interface ScanCameraController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (strong,nonatomic) AVCaptureSession *captureSession;//负责输入和输出设置之间的数据传递
@property (strong,nonatomic) AVCaptureDeviceInput *captureDeviceInput;//负责从AVCaptureDevice获得输入数据
@property (strong,nonatomic) AVCaptureStillImageOutput *captureStillImageOutput;//照片输出流
@property (strong,nonatomic) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;//相机拍摄预览图层
@property (weak, nonatomic) IBOutlet UIView *viewContainer;
@property (weak, nonatomic) IBOutlet UIButton *takeButton;//拍照按钮
@property (weak, nonatomic) IBOutlet UIButton *flashButton;//选择闪光灯按钮
@property (weak, nonatomic) IBOutlet UIButton *flashAutoButton;//自动闪光灯按钮
@property (weak, nonatomic) IBOutlet UIButton *flashOnButton;//打开闪光灯按钮
@property (weak, nonatomic) IBOutlet UIButton *flashOffButton;//关闭闪光灯按钮
@property (weak, nonatomic) IBOutlet UIImageView *focusCursor; //聚焦光标
@end
@implementation ScanCameraController
// 作用:拦截手势触发
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = BLACK_COLOR;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[[[CommonUIAlert alloc] init] showCommonAlertView:self title:@"" message:@"请在iPhone的“设置>隐私>相机”选项中,允许金脉+访问你的相机" cancelButtonTitle:@"取消" otherButtonTitle:@"设置" cancle:^{
[self.navigationController popViewControllerAnimated:YES];
} confirm:^{
if(IOS_X >= 10){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy"]];
}
}];
});
return;
}
}];
//初始化会话
_captureSession=[[AVCaptureSession alloc] init];
if ([_captureSession canSetSessionPreset:AVCaptureSessionPreset1280x720]) {
//设置分辨率,1280x720, 图片的旋转方向是向右
_captureSession.sessionPreset=AVCaptureSessionPreset1280x720;
}
//获得输入设备
AVCaptureDevice *captureDevice = [self getCameraDeviceWithPosition:AVCaptureDevicePositionBack];//取得后置摄像头
if (!captureDevice) {
NSLog(@"取得后置摄像头时出现问题.");
return;
}
//根据输入设备初始化设备输入对象,用于获得输入数据
NSError *error=nil;
_cap
iOS自定义拍照
最新推荐文章于 2021-02-01 05:34:01 发布
本文详细介绍了如何在iOS应用中实现自定义拍照功能,包括设置相机权限、配置相机组件、自定义拍摄界面以及捕获图像的处理流程,旨在帮助开发者打造个性化的拍照体验。
摘要由CSDN通过智能技术生成