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!

individualtermite
  • 3,615
  • 16
  • 49
  • 78
  • 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… – kennytm Jan 24 '10 at 18:52
  • 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. – Ron Srebro Jan 25 '10 at 20:48

9 Answers9

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];
Arie Litovsky
  • 4,893
  • 2
  • 35
  • 40
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];

}
erastusnjuki
  • 1,491
  • 3
  • 14
  • 32
  • Hi erastusnjuki: Thanks for your reply! Can this be implemented in a UIViewController subclass, or does it require something else? – individualtermite Jan 27 '10 at 15:57
  • It should though I haven't tested that.I implemented mine in a UITableViewController that adopts a . – erastusnjuki Jan 27 '10 at 16:11
  • Getting Data formatters temporary not available error during launch in iPhone 4. – BlueDolphin Nov 10 '10 at 15:53
  • 6
    "This will give you a warning. I ignored it." Apple might not be so happy about you using undocumented APIs, however – user102008 Nov 19 '10 at 22:26
  • It works in making the orientation stay landscape right but.. crashes the app. :( – haifacarina Nov 20 '12 at 14:20
  • 6
    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! :) – d4Rk Apr 04 '13 at 07:43
  • Getting error as - No visible @interface for 'UIDevice' declares the selector 'setOrientation:' – Jayprakash Dubey Dec 12 '13 at 10:56
  • Solution for above error is to use following code [At symbol]interface UIDevice () -(void)setOrientation:(UIDeviceOrientation)orientation; [At symbol]end – Jayprakash Dubey Dec 12 '13 at 11:16
  • Really...this one saved my entire project re-work and thanks a lots!! – Jayprakash Dubey Dec 12 '13 at 11:17
  • Rasing Error : No visible @interface for 'UIApplication' declares the selector 'setOrientation:' – Muruganandham K Aug 05 '14 at 07:02
8

If you just need to get rid of the warning try

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end
user567592
  • 181
  • 3
  • 10
  • @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.) – Nate Mar 19 '13 at 20:40
  • @Nate yes, I understand this. That's why I asked these questions. – Dmitry Khryukin Mar 19 '13 at 20:42
  • @DmitryKhryukin, and that's why I answered it. Apple won't accept this, unless you can hide the way you use it. – Nate Mar 19 '13 at 20:44
  • 1
    Getting warning as - Implicit conversion from enumeration type 'enum UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation' (aka 'enum UIDeviceOrientation') – Jayprakash Dubey Dec 12 '13 at 10:58
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

Rich
  • 8,108
  • 5
  • 46
  • 59
2

Make a category of UINavigationController and add this method

- (BOOL)shouldAutorotate
{
    return NO;
}
Kostiantyn Koval
  • 8,407
  • 1
  • 45
  • 58
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.

RhodanV5500
  • 1,087
  • 12
  • 16
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.

GeneCode
  • 7,545
  • 8
  • 50
  • 85
  • 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. – GeneCode Mar 09 '12 at 11:29
0

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

reggian
  • 627
  • 7
  • 21
0

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

alexandrmoroz
  • 337
  • 4
  • 12