Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UIImagePickerController in landscape orientation

I am creating an app which is in landscape mode and I am using UIImagePickerController to take photos using iPhone camera in it and I want to create it in landscape mode too.

But as the Apple documention suggests UIImagePickerController does not support landscape orientation, so what should I do to get desired functionality?

like image 605
Paras Gorasiya Avatar asked Oct 15 '13 06:10

Paras Gorasiya


People also ask

What is use of landscape orientation?

When you are deciding how to frame a picture, you use a vertical or portrait orientation for things like portraits and other vertically-oriented subjects. And you use a horizontal or landscape orientation for horizontal subjects, like a landscape. It is the same with Word.

What is Landscape Design orientation?

Landscape Orientation. Term: Landscape Orientation. Description: Lanscape Orientation is the horizontal orientation in which the long sides of the rectangle are at the top and the bottom, is called landscape. This is because - you guessed it - landscapes, or outdoor photographs - are generally shot this way.

What is the difference between orientation and landscape?

Portrait format refers to a vertical orientation or a canvas taller than it is wide. Landscape usually involves subjects that are too wide to shoot with a portrait orientation, and so, you have to turn the camera sideways, and shoot horizontally.


2 Answers

If you'd like to use UIImagePickerController in landscape mode, use user1673099's answer, but instead of:

- (BOOL)shouldAutorotate {     return NO; } 

use:

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{     return UIInterfaceOrientationMaskLandscape; } 

and then the picker would open in landscape mode:

enter image description here

But make sure you check Portrait in deployment info:

enter image description here

like image 78
iOS.Lover Avatar answered Oct 05 '22 12:10

iOS.Lover


... and I want to create it in landscape mode too.

One line of code can make a big difference! In the method or function where your IBAction lands:

In Swift,

let imagePickerController = UIImagePickerController() imagePickerController.delegate = self // .overCurrentContext allows for landscape and portrait mode imagePickerController.modalPresentationStyle = .overCurrentContext 

Objective-C,

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; [imagePickerController setDelegate:self]; [imagePickerController setModalPresentationStyle: UIModalPresentationOverCurrentContext]; 

Note: This will allow imagePickerController to present it's view correctly, but will may not fix the issue of rotation while it is presented.

like image 20
David Avatar answered Oct 05 '22 13:10

David