In my IOS app, when I open the camera I have placed an image over the camera view. It looks good in portrait mode. But when it is changed to landscape mode it looks some odd. So I want to lock the UIImagePickerController
in Portrait mode.
Following is my code for ui image picker controller
UIImagePickerController *imgPkr = [[UIImagePickerController alloc] init];
imgPkr.delegate = self;
imgPkr.sourceType = UIImagePickerControllerSourceTypeCamera;
How it can be locked in portrait mode....
Just write this code in your view controller
Try this in your view controller. This worked for me. Note: This is for ios6.0 and above
Add a category on
UIImagePickerController
and override it'sshouldAutoRotateToInterfaceOrientation
method, as follows:The only solution that worked for me was the category, but I had to add another method too:
Cheers!
You don't have to "lock the UIImagePicker Controller in Portrait mode". As you said "when it is changed to landscape mode it looks some odd" Actually I don't know why you say it look odd. But, here is my experience of UIImagePicker view look odd in landscape mode. That is: When AViewController as the root view controller. And BViewController's view add subview to AViewController's view. And
presentModalViewController:UIImagePickerController
in BViewController. The UIImagePicker view will look odd in landscape mode.The solution to this problem is set the
UIImagePickerController
as the root view controller before presentModelViewController. The source code below show the detail:I hope this solution can help other person in the future. --Goman
there is no need to create a subclass, just create a category for uiimagepickercontroller and put this line on it - (BOOL)shouldAutorotate{ return NO; }