在人像模式下打开Camera时,UIViewController的横向变化

问题描述

我的iPad应用程序处于横向模式。从ViewController1,我介绍了ViewController2。从那里开始,使用UIImagePicker打开相机(同时将设备保持在纵向模式),ViewController2向下移动了一点,我们可以看到ViewController1旋转为纵向。

enter image description here

代码

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;

BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (hasCamera){
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.showsCameraControls = NO;
    UIView *overlayView = [SCFUtility cameraOverlayViewForBounds:imagePicker.view.bounds withShapeRect:CGSizeMake(400,560) target:self];
    imagePicker.cameraOverlayView = overlayView;
    [overlayView addSubview:self.cameraTimerLabel];
}
else
    imagePicker.sourceType  = UIImagePickerControllerSourceTypePhotoLibrary;

if (imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
    if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
    {
        imagePicker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
    }

    [self.cameraTimerLabel setText:@"9"];
    self.cameraCountDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(cameraCountDownTimerTriggered:) userInfo:nil repeats:YES];
}
else{
    imagePicker.modalPresentationStyle = UIModalPresentationPopover;
    imagePicker.popoverPresentationController.sourceView = self.addPhotoContainerView;
    imagePicker.popoverPresentationController.sourceRect = self.addPhotoContainerView.bounds;
}
[self presentViewController:imagePicker animated:YES completion:nil];
self.imagePickerController = imagePicker;

解决方法

我建议您在以下回调方法(ViewController2和ViewController1)中设置一个断点,以进行大小更改和特征收集更改:

viewWillTransitionToSize:withTransitionCoordinator:
traitCollectionDidChange

并找出触发旋转或视图大小变化的原因。