iPhone/iPad Camera Overlay View AutoRotation Issue UIImagePickerController

431 views Asked by At

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

1

There are 1 answers

0
Ketan Parmar On

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 of UIImagePickerController like swap camera, flash turn on off, take photo or video etc. For that you have to create overlay view and should set as cameraOverlayView of UIImagePickerController. That's it, otherwise you can subclass UIImagePickerController.

So, now solution for your issue :

Subclass UIImagePickerController and in that class implement below two methods like,

 -(BOOL)shouldAutorotate{

    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

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.