diff --git a/LLSimpleCamera/LLSimpleCamera.h b/LLSimpleCamera/LLSimpleCamera.h index 4e9f9f5..0637f09 100644 --- a/LLSimpleCamera/LLSimpleCamera.h +++ b/LLSimpleCamera/LLSimpleCamera.h @@ -116,6 +116,12 @@ typedef enum : NSUInteger { */ @property (nonatomic) BOOL useDeviceOrientation; +/** + * Set YES if you your view controller does not allow autorotation, + * but you want to use the devide orientation on capture. Disabled by default. + */ +@property (nonatomic) BOOL useDeviceOrientationOnCapture; + /** * Use this method to request camera permission before initalizing LLSimpleCamera. */ diff --git a/LLSimpleCamera/LLSimpleCamera.m b/LLSimpleCamera/LLSimpleCamera.m index db75c9f..b0b799f 100644 --- a/LLSimpleCamera/LLSimpleCamera.m +++ b/LLSimpleCamera/LLSimpleCamera.m @@ -75,6 +75,7 @@ - (void)setupWithQuality:(NSString *)quality _fixOrientationAfterCapture = NO; _tapToFocus = YES; _useDeviceOrientation = NO; + _useDeviceOrientationOnCapture = NO; _flash = LLCameraFlashOff; _mirror = LLCameraMirrorAuto; _videoEnabled = videoEnabled; @@ -244,7 +245,7 @@ - (void)initialize if([self.session canAddInput:_videoDeviceInput]) { [self.session addInput:_videoDeviceInput]; - self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false]; } // add audio if video is enabled @@ -305,15 +306,15 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m // get connection and set orientation AVCaptureConnection *videoConnection = [self captureConnection]; - videoConnection.videoOrientation = [self orientationForConnection]; + videoConnection.videoOrientation = [self orientationForConnection:true]; BOOL flashActive = self.videoCaptureDevice.flashActive; if (!flashActive && animationBlock) { animationBlock(self.captureVideoPreviewLayer); } + __weak typeof(self) weakSelf = self; [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { - UIImage *image = nil; NSDictionary *metadata = nil; @@ -331,7 +332,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m image = [self cropImage:image usingPreviewLayer:self.captureVideoPreviewLayer]; } - if(self.fixOrientationAfterCapture) { + if(weakSelf.fixOrientationAfterCapture) { image = [image fixOrientation]; } } @@ -339,7 +340,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m // trigger the block if(onCapture) { dispatch_async(dispatch_get_main_queue(), ^{ - onCapture(self, image, metadata, error); + onCapture(weakSelf, image, metadata, error); }); } }]; @@ -387,8 +388,8 @@ - (void)startRecordingWithOutputUrl:(NSURL *)url didRecord:(void (^)(LLSimpleCam for (AVCaptureInputPort *port in [connection inputPorts]) { // get only the video media types if ([[port mediaType] isEqual:AVMediaTypeVideo]) { - if ([connection isVideoOrientationSupported]) { - [connection setVideoOrientation:[self orientationForConnection]]; + if([connection isVideoOrientationSupported]) { + [connection setVideoOrientation:[self orientationForConnection:true]]; } } } @@ -771,14 +772,14 @@ - (void)viewWillLayoutSubviews self.captureVideoPreviewLayer.bounds = bounds; self.captureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); - self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false]; } -- (AVCaptureVideoOrientation)orientationForConnection +- (AVCaptureVideoOrientation)orientationForConnection: (BOOL) capture { AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait; - if(self.useDeviceOrientation) { + if(self.useDeviceOrientation || (self.useDeviceOrientationOnCapture && capture)) { switch ([UIDevice currentDevice].orientation) { case UIDeviceOrientationLandscapeLeft: // yes to the right, this is not bug! diff --git a/LLSimpleCameraExample.xcodeproj/project.pbxproj b/LLSimpleCameraExample.xcodeproj/project.pbxproj index 9ef72c3..f56154c 100644 --- a/LLSimpleCameraExample.xcodeproj/project.pbxproj +++ b/LLSimpleCameraExample.xcodeproj/project.pbxproj @@ -258,7 +258,6 @@ TargetAttributes = { 17E4C47E1A0122A700E61ACD = { CreatedOnToolsVersion = 6.0.1; - DevelopmentTeam = NZPAC7Q696; }; 17E4C4971A0122A700E61ACD = { CreatedOnToolsVersion = 6.0.1;