individualtermite
individualtermite

Reputation: 3775

UIImagePickerController in Landscape

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!

Upvotes: 23

Views: 32316

Answers (9)

Arie Litovsky
Arie Litovsky

Reputation: 4993

No need to subclass; simply override the modalPresentationStyle property.

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];

Upvotes: 15

RhodanV5500
RhodanV5500

Reputation: 1107

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.

Upvotes: 2

imaginaryunit
imaginaryunit

Reputation: 31

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

Upvotes: 3

reggian
reggian

Reputation: 657

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

Upvotes: 0

Kostiantyn Koval
Kostiantyn Koval

Reputation: 8483

Make a category of UINavigationController and add this method

- (BOOL)shouldAutorotate
{
    return NO;
}

Upvotes: 2

user567592
user567592

Reputation: 181

If you just need to get rid of the warning try

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end

Upvotes: 8

GeneCode
GeneCode

Reputation: 7588

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.

Upvotes: 2

alexandrmoroz
alexandrmoroz

Reputation: 386

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

Upvotes: 0

erastusnjuki
erastusnjuki

Reputation: 1511

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

}

Upvotes: 13

Related Questions