自动布局指南:UIImagePickerController W /自定义叠加不会旋转

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动布局指南:UIImagePickerController W /自定义叠加不会旋转相关的知识,希望对你有一定的参考价值。

我有一个带有自定义叠加层的UIImagePickerController。在叠加层的nib文件中,我为两个不同大小的类设置了UI约束,wc hR用于纵向,wC hC用于横向。为正确的大小类安装每个约束。

但是,当我转动相机风景时它不会旋转。我这样设置我的UIImagePickerController

- (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];

}
答案

来自Apple的文档:

重要

UIImagePickerController类仅支持纵向模式。

参考:https://developer.apple.com/documentation/uikit/uiimagepickercontroller?language=objc

以上是关于自动布局指南:UIImagePickerController W /自定义叠加不会旋转的主要内容,如果未能解决你的问题,请参考以下文章

自动布局指南:UIImagePickerController W /自定义叠加不会旋转

界面生成器中的自动布局

与顶部布局指南和底部布局指南的距离相等

使用自动布局以编程方式添加背景图像视图

如何在 ScrollView 中为 ImageView 设置自动布局约束?

iOS7隐藏状态栏但不调整顶部布局指南