|
@@ -49,8 +49,39 @@
|
|
|
[self.takePhotoBtn setImage:normal_img forState:UIControlStateNormal];
|
|
[self.takePhotoBtn setImage:normal_img forState:UIControlStateNormal];
|
|
|
[self.takePhotoBtn setImage:highlight_img forState:UIControlStateHighlighted];
|
|
[self.takePhotoBtn setImage:highlight_img forState:UIControlStateHighlighted];
|
|
|
|
|
|
|
|
- [self initCapture];
|
|
|
|
|
- [self initTakePicture];
|
|
|
|
|
|
|
+// [self initCapture];
|
|
|
|
|
+// [self initTakePicture];
|
|
|
|
|
+
|
|
|
|
|
+ if ([self camerAuthorization]) {
|
|
|
|
|
+
|
|
|
|
|
+ [self initCapture];
|
|
|
|
|
+ [self initTakePicture];
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // fix:第一次打开相机的时候授权成功后,未初始化相机
|
|
|
|
|
+ [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
|
|
|
|
+
|
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
+ if (granted) {
|
|
|
|
|
+ [self initCapture];
|
|
|
|
|
+ [self initTakePicture];
|
|
|
|
|
+
|
|
|
|
|
+ CGRect frame = self.previewContainer.bounds;
|
|
|
|
|
+ [self resetPreview:CGRectOffset(frame, CGRectGetWidth(frame), 0)];
|
|
|
|
|
+
|
|
|
|
|
+ [UIView animateWithDuration:0.3 animations:^{
|
|
|
|
|
+ self.previewLayer.frame = frame;
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ if (self.cameraInitial && !self.captureSession.isRunning) {
|
|
|
|
|
+ [self.captureSession startRunning];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
- (void)didReceiveMemoryWarning {
|
|
@@ -61,7 +92,7 @@
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
[super viewWillAppear:animated];
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
- if (self.cameraInitial) {
|
|
|
|
|
|
|
+ if (self.cameraInitial && !self.captureSession.isRunning) {
|
|
|
[self.captureSession startRunning];
|
|
[self.captureSession startRunning];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -77,7 +108,17 @@
|
|
|
- (void)viewDidLayoutSubviews {
|
|
- (void)viewDidLayoutSubviews {
|
|
|
[super viewDidLayoutSubviews];
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
|
|
- self.previewLayer.frame = self.previewContainer.bounds;
|
|
|
|
|
|
|
+ if ([self camerAuthorization] && self.cameraInitial) {
|
|
|
|
|
+
|
|
|
|
|
+ [self resetPreview:self.previewContainer.bounds];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark - Capture
|
|
|
|
|
+
|
|
|
|
|
+- (void)resetPreview:(CGRect)frame {
|
|
|
|
|
+
|
|
|
|
|
+ self.previewLayer.frame = frame;
|
|
|
|
|
|
|
|
if (self.previewLayer.connection.isVideoOrientationSupported) {
|
|
if (self.previewLayer.connection.isVideoOrientationSupported) {
|
|
|
self.previewLayer.connection.videoOrientation = [self captureVideoOrientation];
|
|
self.previewLayer.connection.videoOrientation = [self captureVideoOrientation];
|
|
@@ -86,10 +127,9 @@
|
|
|
if ([self.captureOutput connectionWithMediaType:AVMediaTypeVideo].isVideoOrientationSupported) {
|
|
if ([self.captureOutput connectionWithMediaType:AVMediaTypeVideo].isVideoOrientationSupported) {
|
|
|
[self.captureOutput connectionWithMediaType:AVMediaTypeVideo].videoOrientation = [self captureVideoOrientation];
|
|
[self.captureOutput connectionWithMediaType:AVMediaTypeVideo].videoOrientation = [self captureVideoOrientation];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#pragma mark - Capture
|
|
|
|
|
-
|
|
|
|
|
- (BOOL)camerAuthorization {
|
|
- (BOOL)camerAuthorization {
|
|
|
|
|
|
|
|
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|