Please note that the answer below - do not work for iOS6 so I still need an answer!
My application is enabled only for Portrait mode.
However, if I embed a UIImagePickerController inside as a subview, and rotate the device, the top and bottom bar stays in the same location, however UIImagePickerController does rotate.
How can I prevent it from rotating?
This is the code:
[self.view.window addSubview:self.imagePickerController.view];
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.view.frame = CGRectMake(0, 90, 320, 320);
self.imagePickerController.allowsEditing = NO;
EDITED
I am using iOS6 where shouldAutorotate is not being calle
Add this
UIImagePickerController
category in your class,include the following in your controller this will work, I'm just creating the category of
UIImagePickerController
The category in the most voted answer works, but since it is discouraged to use categories, you can also make a subclass of UIImagePickerController and use that.
If you want to avoid rotating of the UIImagePickerController add the following class
UINonRotatableImagePickerController.h
UINonRotatableImagePickerController.m
You have to change the UIImagePicker class in the storyboard to use UILandscapeImagePickerController, or if you allocate it in code, change
to
and include UINonRotatableImagePickerController.h in your code.
One possibility is to override the
method of
UIImagePickerController
. I'm not sure if this is the best possibility but it will work.So if you only want your UIImagePickerController to be rotated to portrait use the following code
And the implementation should look like the following