UIImagePickerController in Landscape
Solution 1
I haven't checked whether this is illegal, but it worked for me. If you want the UIImagePickerController to start(and stay) in Landscape orientation code:
//Initialize picker
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//Refer to the method didRotate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
//Set the picker source as the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Bring in the picker view
[self presentModalViewController:picker animated:YES];
The method didRotate:
- (void) didRotate:(NSNotification *)notification
{
//Maintain the camera in Landscape orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
Solution 2
No need to subclass; simply override the modalPresentationStyle
property.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
[viewController presentViewController:picker animated:YES completion:NULL];
Solution 3
If you just need to get rid of the warning try
@interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
@end
Solution 4
I've developed a UIImagePicker class in landscape mode. Works great for applications I've developed: hope it works for you too:
GitHub: https://github.com/imaginaryunit/iOSLandscapeThreadedImagePicker.git
Solution 5
Subclass UIImagePickerController
and override modalPresentationStyle
as follows:
- (UIModalPresentationStyle)modalPresentationStyle
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return UIModalPresentationFormSheet;
}
return [super modalPresentationStyle];
}
The image-picker is a form-sheet now and no longer in fullscreen-mode, but it looks good in landscape-mode. This should be totally app-store-safe.
This works for the gallery, not for taking pictures.
Related videos on Youtube
PF1
Updated on July 09, 2022Comments
-
PF1 almost 2 years
I have been searching for an answer to this, but cannot come up with anything. Apparently, iPhone SDK 3.0 made it possible that UIImagePickerController can be displayed in landscape mode - but I am not finding any method that will allow this. I would think that if the application is in landscape by default it would automatically adjust the image controller, but that is not working for me.
Thanks for any help!
-
kennytm over 14 yearsGiven the built-in Photos app's image picker doesn't support landscape, your chance of having a landscape image picker is slim, and I can't think of an SDK-safe way to get the content of photo album…
-
Ron Srebro over 14 yearsAs KennyTM mentions, the built in photos app doesn't work in landscape mode. What made you think that SDK 3.0 made it possible to use the picker in landscape mode? Maybe if you share it with us it will give us a hint on how to go about it.
-
-
PF1 over 14 yearsHi erastusnjuki: Thanks for your reply! Can this be implemented in a UIViewController subclass, or does it require something else?
-
erastusnjuki over 14 yearsIt should though I haven't tested that.I implemented mine in a UITableViewController that adopts a <UIImagePickerControllerDelegate>.
-
PF1 over 14 yearsHi Alexandr: Even if I create the UIImagePickerController when the application is set to run in only landscape mode, it still shows up as vertically.
-
BlueDolphin over 13 yearsGetting Data formatters temporary not available error during launch in iPhone 4.
-
user102008 over 13 years"This will give you a warning. I ignored it." Apple might not be so happy about you using undocumented APIs, however
-
GeneCode about 12 yearsJust to add, this is no longer a problem since iOS4. The ImagePickerController automatically shows itself in portrait format even when you're in landscape.
-
haifacarina over 11 yearsIt works in making the orientation stay landscape right but.. crashes the app. :(
-
Nate about 11 years@DmitryKhryukin, this is a private API, and will almost certainly be rejected in an App Store app (unless you want to try to obfuscate the
setOrientation:
selector, and sneak it in.) -
Dmitry Khryukin about 11 years@Nate yes, I understand this. That's why I asked these questions.
-
Nate about 11 years@DmitryKhryukin, and that's why I answered it. Apple won't accept this, unless you can hide the way you use it.
-
d4Rk about 11 yearsI managed to get the picker showing up in landscape, BUT the camera (live) image is 90° rotated, so you can't really use this to take any photos, as if you move the iPhone horizontal you will see a vertical movement in the camera screen / image and the other way round. Did someone else face this problem or even has a fix for that? Thanks in advance for any help! :)
-
Jayprakash Dubey over 10 yearsGetting error as - No visible @interface for 'UIDevice' declares the selector 'setOrientation:'
-
Jayprakash Dubey over 10 yearsGetting warning as - Implicit conversion from enumeration type 'enum UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation' (aka 'enum UIDeviceOrientation')
-
Jayprakash Dubey over 10 yearsSolution for above error is to use following code [At symbol]interface UIDevice () -(void)setOrientation:(UIDeviceOrientation)orientation; [At symbol]end
-
Jayprakash Dubey over 10 yearsReally...this one saved my entire project re-work and thanks a lots!!
-
AsifHabib about 10 yearsiOS 7 is the main problem! every thing was working fine in iOS 6
-
Muruganandham K over 9 yearsRasing Error : No visible @interface for 'UIApplication' declares the selector 'setOrientation:'
-
Jeff about 8 yearsI know its 3 years later but your project shows a black screen. Just letting you know.
-
reggian about 8 yearsThanks, I'll add it to my ToDo list:)
-
LeXeR almost 8 yearsi would make this as accepted answer. Use
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
for better results. -
Roman B. almost 7 years@LeXeR works great! Also, UIModalPresentationCustom will fix landscape presentation on iPad.
-
Dan Selig over 6 yearsswift: picker.modalPresentationStyle = .currentContext