According to Apple, we must not subclass the UIImagePickerController
class. From the docs:
Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
But If we want to overlay a view on the camera, we can do so as follows:
imagePickerController.cameraOverlayView = overlayView
After implementing the camera overlay view, The view adjusts itself automatically in iPads. However, this is not the case with the iPhones.
Query: Can we set the autorotation of the cameraOverlayView in iPhone as in iPad?
If not, what is the optimum way of rotating the cameraOverlayView with UIDeviceOrientationDidChangeNotification
You can subclass
UIImagePickerController
and can instantiate it. Apple saying that you should not subsclass it is for other reason. You can not change default controls ofUIImagePickerController
like swap camera, flash turn on off, take photo or video etc. For that you have to createoverlay view
and should set ascameraOverlayView
ofUIImagePickerController
. That's it, otherwise you can subclassUIImagePickerController
.So, now solution for your issue :
Subclass
UIImagePickerController
and in that class implement below two methods like,and then instantiate that class instead of
UIImagePickerController
.and your orientation issue for your overlayview will be solved. It will always remain in portrait mode.