I have an app in "Landscape" mode. I want to open my camera in "Landscape" mode only.
I have already tried UIImagePickerController
.
It works in iOS 6 but it does not support landscape mode in iOS 7.
What is the solution for this?

- 4,011
- 6
- 36
- 56
-
use this group for questions and solutions **iOS Development Issues** – Rohan Jul 29 '16 at 09:41
-
@Rohan please accept my request – Jul 29 '16 at 09:49
5 Answers
Please try this code.
It's solved my problem.
UIImagePickerController *yourpicker = [[UIImagePickerController alloc] init];
yourpicker.delegate = self;
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(makeLandscape:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
yourpicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:yourpicker animated:YES];
- (void)makeLandscape:(NSNotification *)notification
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
I think its showing some warning about setOrientation, but ignore that warning.

- 4,817
- 2
- 26
- 51
You'll need to use AVFoundation
. Here's a good starting point for you:
#import "HSViewController.h"
@import AVFoundation;
@interface HSViewController ()
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@end
@implementation HSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (error)
{
NSLog(@"Error: %@", error);
}
else
{
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
[captureSession addInput:input];
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
self.previewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:self.previewLayer];
[captureSession startRunning];
}
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
self.previewLayer.frame = self.view.bounds;
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIInterfaceOrientationLandscapeLeft:
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
}
}
@end

- 7,251
- 1
- 27
- 32
Here is another approach you would be interested in. You might implement your own custom camera view controller using AVFoundation framework. In this case you need to create all controls, preview layer, handle focusing yourself. It can be a little difficult if you don't familiar with AVFoundation. Here are good references.
About the Camera and Photo Library
AV Foundation Programming Guide
Apple's sample code (good example)

- 1,649
- 1
- 14
- 13
in your viewController.h:
@interface TakePhotoViewController : UIViewController <UIImagePickerControllerDelegate>
@end
in your viewController.m
@implementation TakePhotoViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
@end

- 742
- 1
- 5
- 22
-
what do you mean with it does work ???? it does not support landscape mode only or at all ??? – poyo fever. May 20 '14 at 13:27
you can add a category on UIImagePickerController to remove Rotation like this :
UIImagePickerController+RemoveRotation.h
#import <UIKit/UIKit.h>
@interface UIImagePickerController (RemoveRotation)
@end
UIImagePickerController+RemoveRotation.h
#import "UIImagePickerController+RemoveRotation.h"
@implementation UIImagePickerController (RemoveRotation)
- (BOOL)shouldAutorotate
{
return NO;
}
@end
I hope it will help you my friend.

- 742
- 1
- 5
- 22