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

时间:2018-03-02 16:40:12

标签: ios objective-c rotation uiimagepickercontroller

我有一个带自定义叠加层的UIImagePickerController。在叠加层的nib文件中,我为两个不同大小的类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];

}

1 个答案:

答案 0 :(得分:0)

来自Apple的文档:

  

重要

     

UIImagePickerController类仅支持纵向模式。

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