Skip to content

Commit 80af830

Browse files
committed
Add flag to use device orientation only on capture
1 parent 2cf2d78 commit 80af830

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

LLSimpleCamera/LLSimpleCamera.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ typedef enum : NSUInteger {
116116
*/
117117
@property (nonatomic) BOOL useDeviceOrientation;
118118

119+
/**
120+
* Set YES if you your view controller does not allow autorotation,
121+
* but you want to use the devide orientation on capture. Enabled by default.
122+
*/
123+
@property (nonatomic) BOOL useDeviceOrientationOnCapture;
124+
119125
/**
120126
* Use this method to request camera permission before initalizing LLSimpleCamera.
121127
*/

LLSimpleCamera/LLSimpleCamera.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ - (void)setupWithQuality:(NSString *)quality
7474
_fixOrientationAfterCapture = NO;
7575
_tapToFocus = YES;
7676
_useDeviceOrientation = NO;
77+
_useDeviceOrientationOnCapture = YES;
7778
_flash = LLCameraFlashOff;
7879
_mirror = LLCameraMirrorAuto;
7980
_videoEnabled = videoEnabled;
@@ -250,7 +251,7 @@ - (void)initialize
250251

251252
if([self.session canAddInput:_videoDeviceInput]) {
252253
[self.session addInput:_videoDeviceInput];
253-
self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection];
254+
self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false];
254255
}
255256

256257
// add audio if video is enabled
@@ -313,7 +314,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m
313314

314315
// get connection and set orientation
315316
AVCaptureConnection *videoConnection = [self captureConnection];
316-
videoConnection.videoOrientation = [self orientationForConnection];
317+
videoConnection.videoOrientation = [self orientationForConnection:true];
317318

318319
// freeze the screen
319320
[self.captureVideoPreviewLayer.connection setEnabled:NO];
@@ -382,7 +383,7 @@ - (void)startRecordingWithOutputUrl:(NSURL *)url
382383
// get only the video media types
383384
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
384385
if([connection isVideoOrientationSupported]) {
385-
[connection setVideoOrientation:[self orientationForConnection]];
386+
[connection setVideoOrientation:[self orientationForConnection:false]];
386387
}
387388
}
388389
}
@@ -846,14 +847,14 @@ - (void)viewWillLayoutSubviews
846847
self.captureVideoPreviewLayer.bounds = bounds;
847848
self.captureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
848849

849-
self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection];
850+
self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false];
850851
}
851852

852-
- (AVCaptureVideoOrientation)orientationForConnection
853+
- (AVCaptureVideoOrientation)orientationForConnection: (BOOL) capture
853854
{
854855
AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait;
855856

856-
if(self.useDeviceOrientation) {
857+
if(self.useDeviceOrientation || (self.useDeviceOrientationOnCapture && capture)) {
857858
switch ([UIDevice currentDevice].orientation) {
858859
case UIDeviceOrientationLandscapeLeft:
859860
// yes we to the right, this is not bug!

0 commit comments

Comments
 (0)