8

I've been trying to sort this one out for a while and getting nowhere.

I'm using the camera on the iPad 2 - my application is in landscape, but I want to use the camera in portrait mode. I just can't seem to force the ImagePicker a, into Portrait mode, and b, to stop auto-rotating.

Is there any way that you can force the ImagePicker into portrait (or landscape), and/or to stop it auto-rotating?

Even though the App is in landscape and is set to return YES only to landscape orientations, the ImagePicker ignores that and rotates into portrait when you rotate the iPad 2.

If I could force it into staying in landscape then (although not ideal) I could re-design the app to use the camera in landscape, but I don't seem to be able to do even that!

Any help greatly appreciated!

Matt
  • 81
  • 1
  • 4

2 Answers2

1

The method that you need to override called:

_isSupportedInterfaceOrientation:

So it should look something like this :

@interface PortraitImagePickerController : UIImagePickerController {

}

@end





@implementation PortraitImagePickerController
- (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation{
    return UIDeviceOrientationIsPortrait(orientation);
}
@end

But it's definitely private method so Apple may reject your app

Dmitry
  • 1,035
  • 2
  • 14
  • 27
  • Thanks for that - what I did in the end was a bit of a fudge - when the device is rotated out of portrait, I closed the ImagePicker and displayed an image suggesting rotating the device back into portrait - Apple passed it, but I don't really like the solution. – Matt Jun 21 '11 at 09:10
  • This is exactly what I need. Anybody know if this will get my app rejected? – theDuncs Jun 19 '12 at 14:54
  • our app was accepted with this. although - it is a risk to use it anyway – Dmitry Jun 22 '12 at 20:12
0

Well i have found a more convenient way and has no risk of using private code.

Sub class a UIImagePickerController and add following method in its .m file.

- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}
Umair
  • 400
  • 5
  • 19