views:

859

answers:

3

Hi Everyone:

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!

A: 

Check this thread:

http://stackoverflow.com/questions/538041/uiimagepickercontroller-camera-preview-is-portrait-in-landscape-app

David Sowsy
Hi David: Is this for the whole UIImagePickerController, or simply the UIImage returned?
PF1
+2  A: 

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
Hi erastusnjuki: Thanks for your reply! Can this be implemented in a UIViewController subclass, or does it require something else?
PF1
It should though I haven't tested that.I implemented mine in a UITableViewController that adopts a <UIImagePickerControllerDelegate>.
erastusnjuki
A: 

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

xzDeveloper
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.
PF1