Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lock UIImagePickerController in Portrait mode in ios app

In my IOS app, when I open the camera I have placed an image over the camera view. It looks good in portrait mode. But when it is changed to landscape mode it looks some odd. So I want to lock the UIImagePickerController in Portrait mode.

Following is my code for ui image picker controller

UIImagePickerController *imgPkr = [[UIImagePickerController alloc] init];
imgPkr.delegate = self;
imgPkr.sourceType = UIImagePickerControllerSourceTypeCamera;

How it can be locked in portrait mode....

like image 291
Siva K Avatar asked Jan 20 '12 11:01

Siva K


2 Answers

Or, you can subclass the UIImagePickerController:

Create a new UIImagePickerController class and just add these lines to it.

- (BOOL)shouldAutorotate{
return NO;
}

Import it to the class that uses the camera and instead of using default UIImagePickerController, use the class that you created.

Your camera itself should stop from auto rotating.

like image 164
aalesano Avatar answered Sep 22 '22 19:09

aalesano


This is not the best solution, but it works:

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:cameraOverlay];
imgPicker.cameraOverlayView = appDelegate.window.superview;

The camera on the background still rotates, but your overlay view doesn´t. Hope it works for you

like image 20
ZiggyST Avatar answered Sep 25 '22 19:09

ZiggyST