I have a UIImagePickerController with a custom overlay. In the nib file for the overlay, I set UI constraints for two different size classes wc hR
for portrait and wC hC
for landscape. Each constraint is installed for the correct size class.
However, it won't rotate when I turn the camera landscape. I set up my UIImagePickerController
like so:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
ipc.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
ipc.cameraViewTransform = CGAffineTransformScale(ipc.cameraViewTransform, scale, scale);
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = YES;
[ipc setAllowsEditing:YES];
}else{
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:ipc animated:YES completion:nil];
[_activityIndicator stopAnimating];
}
From Apple's docs:
Important
The UIImagePickerController class supports portrait mode only.
Ref: https://developer.apple.com/documentation/uikit/uiimagepickercontroller?language=objc