In my landscape-only iPhone application, I launch a UIImagePickerController to take a photo, but the live image displayed from the camera is in portrait orientation, with blank space around it. The image is rotated.
Once the camera button is pressed, the preview is very messy, with most of the preview off screen, and views not correctly aligned.
Apple has acknowledged that this is defect, and is working on it.
My question is, does anyone have a work-around (legal or illegal) that would allow me to get this working now. I wouldn't release to the App Store with an illegal fix, but I would have a much better app for user testing - currently the camera is pretty much unusable in landscape.
I will attach a simple test project and images if I can.
Edit - just to clarify, the image I get is correctly landscape. I want the camera & preview UIs to look right!
I don't want to rotate the image after capture; I want to have the preview show correctly in landscape mode. So in iOS 6, I allow portrait mode at the application level, but set the app's root view controller to be of class
MyNonrotatingNavigationController
, defined as follows:So everything that's ever shown inside this nav controller will be in landscape orientation (you could do this with any view controller). Now, when I need to show an image picker, I replace the app window's root view controller with a generic one that supports portrait mode. To prevent the old root view controller and its views from deallocating, I maintain pointers to them until I'm ready to put them back in the app window.
Kind of a pain, but it does seem to work for both photos and videos. The image picker's controls show in portrait mode, but the rest of the app is landscape-only.
You'll need to set custom view (with toolbar and title) as
cameraOverlayView
, also you'll need to setallowsEditing
andshowsCameraControls
toNO
as that will hide standard controls and the preview. That's what I've found as necessary in app I'm making (thought I need the picker to be in portrait, but I need it to apply some ui changes if user rotate his device to landscape).Code may be provided if there's need for it.
P.S. There are still some bugs in my code, but I'm working on it :)
Let me know if this is discouraged re-posting the best answer above, I have a 2019 swift version for Alex Wayne's answer.
The answer is more ridiculous than you might think. I had the same problem and found a solution in a forum somewhere. Pass your taken image into a method like this:
:(
I solved this issue by making the
UIImagePickerController
appear in full-screen mode, which is also what Apple recommends for iPad.From
UIImagePickerController
documentation:I don't think that you need the extra work to deal with imageRotation or the EXIF data at all. Image drawInRect will take care of that automatically.
So, you only need to get this size or the image and redraw it to a new image, that would be enough.