Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LLSimpleCamera/LLSimpleCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
21 changes: 11 additions & 10 deletions LLSimpleCamera/LLSimpleCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ - (void)setupWithQuality:(NSString *)quality
_fixOrientationAfterCapture = NO;
_tapToFocus = YES;
_useDeviceOrientation = NO;
_useDeviceOrientationOnCapture = NO;
_flash = LLCameraFlashOff;
_mirror = LLCameraMirrorAuto;
_videoEnabled = videoEnabled;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -331,15 +332,15 @@ -(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];
}
}

// trigger the block
if(onCapture) {
dispatch_async(dispatch_get_main_queue(), ^{
onCapture(self, image, metadata, error);
onCapture(weakSelf, image, metadata, error);
});
}
}];
Expand Down Expand Up @@ -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]];
}
}
}
Expand Down Expand Up @@ -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!
Expand Down
1 change: 0 additions & 1 deletion LLSimpleCameraExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@
TargetAttributes = {
17E4C47E1A0122A700E61ACD = {
CreatedOnToolsVersion = 6.0.1;
DevelopmentTeam = NZPAC7Q696;
};
17E4C4971A0122A700E61ACD = {
CreatedOnToolsVersion = 6.0.1;
Expand Down