UIImagePickerController in Landscape
Asked Answered
F

9

23

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!

Furl answered 18/1, 2010 at 3:3 Comment(2)
Given 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…Hiltan
As 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.Pekingese
P
13

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];

}
Prothalamion answered 27/1, 2010 at 14:29 Comment(10)
Hi erastusnjuki: Thanks for your reply! Can this be implemented in a UIViewController subclass, or does it require something else?Furl
It should though I haven't tested that.I implemented mine in a UITableViewController that adopts a <UIImagePickerControllerDelegate>.Prothalamion
Getting Data formatters temporary not available error during launch in iPhone 4.Aerostat
"This will give you a warning. I ignored it." Apple might not be so happy about you using undocumented APIs, howeverHeadpin
It works in making the orientation stay landscape right but.. crashes the app. :(Tumescent
I 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! :)Dunghill
Getting error as - No visible @interface for 'UIDevice' declares the selector 'setOrientation:'Pitman
Solution for above error is to use following code [At symbol]interface UIDevice () -(void)setOrientation:(UIDeviceOrientation)orientation; [At symbol]endPitman
Really...this one saved my entire project re-work and thanks a lots!!Pitman
Rasing Error : No visible @interface for 'UIApplication' declares the selector 'setOrientation:'Decentralization
A
15

No need to subclass; simply override the modalPresentationStyle property.

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];
Amidst answered 23/9, 2014 at 19:34 Comment(3)
i would make this as accepted answer. Use picker.modalPresentationStyle = UIModalPresentationCurrentContext; for better results.Bliss
@Bliss works great! Also, UIModalPresentationCustom will fix landscape presentation on iPad.Pickering
swift: picker.modalPresentationStyle = .currentContextPlainlaid
P
13

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];

}
Prothalamion answered 27/1, 2010 at 14:29 Comment(10)
Hi erastusnjuki: Thanks for your reply! Can this be implemented in a UIViewController subclass, or does it require something else?Furl
It should though I haven't tested that.I implemented mine in a UITableViewController that adopts a <UIImagePickerControllerDelegate>.Prothalamion
Getting Data formatters temporary not available error during launch in iPhone 4.Aerostat
"This will give you a warning. I ignored it." Apple might not be so happy about you using undocumented APIs, howeverHeadpin
It works in making the orientation stay landscape right but.. crashes the app. :(Tumescent
I 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! :)Dunghill
Getting error as - No visible @interface for 'UIDevice' declares the selector 'setOrientation:'Pitman
Solution for above error is to use following code [At symbol]interface UIDevice () -(void)setOrientation:(UIDeviceOrientation)orientation; [At symbol]endPitman
Really...this one saved my entire project re-work and thanks a lots!!Pitman
Rasing Error : No visible @interface for 'UIApplication' declares the selector 'setOrientation:'Decentralization
M
8

If you just need to get rid of the warning try

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end
Meldameldoh answered 11/4, 2011 at 21:8 Comment(4)
@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.)Unbend
@Unbend yes, I understand this. That's why I asked these questions.Spaceship
@DmitryKhryukin, and that's why I answered it. Apple won't accept this, unless you can hide the way you use it.Unbend
Getting warning as - Implicit conversion from enumeration type 'enum UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation' (aka 'enum UIDeviceOrientation')Pitman
A
3

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

Arcadian answered 27/2, 2012 at 18:58 Comment(0)
C
2

I have an all-landscape app using UIImagePickerController too. Please be noted that if you call UIImagePickerController in Landscape mode, your app is possible to be rejected by Apple Review Team.

I devised a simple work around this issue which make use the shouldAutoRotate delegate. Apple approves this method for an all-landscape app.

See here for the details and downloadable full project source code.

Chimera answered 17/1, 2011 at 5:11 Comment(1)
Just to add, this is no longer a problem since iOS4. The ImagePickerController automatically shows itself in portrait format even when you're in landscape.Chimera
V
2

Make a category of UINavigationController and add this method

- (BOOL)shouldAutorotate
{
    return NO;
}
Volding answered 15/5, 2013 at 9:33 Comment(0)
A
2

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.

Ader answered 28/5, 2014 at 12:28 Comment(0)
B
0

I solved this problem as follows: after each change in orientation, I simple re-create picker. Try this. Differently is too crooked...

Bramwell answered 29/1, 2010 at 16:47 Comment(2)
Hi Alexandr: Even if I create the UIImagePickerController when the application is set to run in only landscape mode, it still shows up as vertically.Furl
iOS 7 is the main problem! every thing was working fine in iOS 6Schrader
P
0

I am developing a class that tries its best to work in landscape mode. Check it out on GitHub: RACameraController

Pittman answered 9/10, 2013 at 11:59 Comment(2)
I know its 3 years later but your project shows a black screen. Just letting you know.Rhinoceros
Thanks, I'll add it to my ToDo list:)Pittman

© 2022 - 2024 — McMap. All rights reserved.