7

I am using Imagepicker overlay to capture photos. In iOS 9 my code works fine, but when I run my code on iOS 10 it shows a space at the bottom which is not displayed on iOS 9 . I tried to solve it but I am not able to do it.

Here is my code that generates the issue:

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

Here is the screenshot enter image description here

Update:

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.

UIImagePickerController's cameraViewTransform is ignoring 'scaling' and 'translation' on iOS 10 beta

Community
  • 1
  • 1
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61

3 Answers3

1

@chirag shah I did not found great solution for imagePicker transform in ios10. I just omitted imagepicker from my ios 10 project and use AVCaptureSession with video gravity AVLayerVideoGravityResizeAspectFill for AVCaptureVideoPreviewLayer object. It's work perfectly.

Andrew Veresov
  • 321
  • 1
  • 6
0

What is transparentView in your presentPicker method? Try setting it's frame like this:

transparentView.frame = imagePickerController.view.bounds;
imagePickerController.cameraOverlayView = transparentView;
[self presentViewController:imagePickerController animated:YES completion:nil];
alexburtnik
  • 7,661
  • 4
  • 32
  • 70
0

Actually I faced same problem. As I couldn't find a proper solution, I just transformed the view's ty like

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, sizeMissingAtBottom);
imagePickerController.cameraViewTransform = translate;

You can then CGAffineTransformScale the translate if needed.

icould
  • 315
  • 3
  • 9