Imagepicker叠加层不会仅在ios 10中全屏显示

chi*_*hah 7 objective-c ios ios10

我正在使用Imagepicker叠加来捕捉照片.在iOS 9中,我的代码工作正常,但是当我在iOS 10上运行我的代码时,它在底部显示了一个空间,而这个空间在iOS 9上没有显示.我试图解决它,但我无法做到.

这是我生成问题的代码:

- (void)openCamerawithOption :(UIImagePickerControllerCameraCaptureMode)camType
{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {

        [[NSOperationQueue mainQueue] addOperation:[NSBlockOperation blockOperationWithBlock:^{
            [self createImagePicker:camType];
        }]];
    }
}

-(void)createImagePicker :(UIImagePickerControllerCameraCaptureMode)camType
{
    if (!imagePickerController) {
        imagePickerController = [[NonRotatableImagePickerController alloc] init];
    }
    //[imagePickerController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+(iOS7?0:20.0))];
    [APPSINGLETON setBorder:imagePickerController.view color:[UIColor redColor]];

    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.allowsEditing = YES;
    imagePickerController.videoMaximumDuration = 60.0;

    if (iOS7) {
        CGSize screenBounds = APPDELEGATE.screenSize;
        CGFloat cameraAspectRatio = 4.0f/3.0f;
        CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
        CGFloat scale = screenBounds.height / camViewHeight;
        imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
        imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, scale, scale);
    } else {
        float cameraAspectRatio = 4.0 / 3.0;
        float imageWidth = floorf(APPDELEGATE.screenSize.width * cameraAspectRatio);
        float scale = ceilf(((APPDELEGATE.screenSize.height+20.0) / imageWidth) * 10.0) / 10.0;
        imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
    }

    imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString )kUTTypeMovie, (NSString )kUTTypeImage, nil];
    imagePickerController.cameraCaptureMode = camType;
    imagePickerController.showsCameraControls = NO;
    imagePickerController.toolbar.hidden=YES;
    imagePickerController.wantsFullScreenLayout = YES;

    // not all devices have two cameras or a flash so just check here
    if ([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear])
    {
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    }
    else
    {
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    }

    if ([UIImagePickerController isFlashAvailableForCameraDevice:imagePickerController.cameraDevice])
    {
        imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
    }

    [self performSelectorOnMainThread:@selector(presentPicker) withObject:nil waitUntilDone:YES];
}

-(void)presentPicker
{
    [self presentViewController:imagePickerController animated:YES completion:nil];
    imagePickerController.cameraOverlayView = transparentView;
} 
Run Code Online (Sandbox Code Playgroud)

这是截图 在此输入图像描述

更新:

self.presentViewController(
        self.imagePicker,
        animated: true,
        completion: {
            let screenSize = UIScreen.mainScreen().bounds.size
            let ratio: CGFloat = 4.0 / 3.0
            let cameraHeight: CGFloat = screenSize.width * ratio
            let scale: CGFloat = screenSize.height / cameraHeight

            self.imagePicker.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0)
            self.imagePicker.cameraViewTransform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, scale, scale)
        }
    )

This solution from below is working for me except when I rotate the device the same issue returns.
Run Code Online (Sandbox Code Playgroud)

UIImagePickerController的cameraViewTransform忽略了iOS 10 beta上的"缩放"和"翻译"

小智 1

@chirag shah 我没有找到 ios10 中 imagePicker 转换的很好的解决方案。我刚刚从我的 ios 10 项目中省略了 imagepicker,并使用 AVCaptureSession 和视频重力 AVLayerVideoGravityResizeAspectFill 作为 AVCaptureVideoPreviewLayer 对象。工作完美。