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?
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.
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.
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.
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:
But make sure you check Portrait in deployment info:
... 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With