Search code examples
iosxcodeswiftuiimageuiimagepickercontroller

UIImagePickerController Camera Overlay that matches the default cropping


Here's my problem. I'm using UIImagePickerController to take a picture from the camera. After it's been taken (and because I set allowsEditing to TRUE), the preview image shows a white rectangle delimiting the default cropping area (which doesn't appear to be in the center of the picture).

What I want is to set a custom Camera Overlay that matches exactly that cropping area so that the user knows exactly that the picture he took will be the resulting image after cropping.

See picture below, basically I want the Camera Overlay to only display the red rectangle that represents the cropping rectangle in the preview. enter image description here

Any idea on how to implement this so it will work on all type of Iphone device (iphone 4, 5, 6, 6 plus) and Portrait/Landscape mode ?

Thanks for your help.


Solution

  • You can use the following 3rd party library https://github.com/gekitz/GKImagePicker

    self.myPicker = [[GKImagePicker alloc] init];
    
    self.myPicker.delegate = self;
    
    self.myPicker.cropSize = CGSizeMake([FunctionUtils getViewWidth], [FunctionUtils getViewWidth]/ratio);
    

    and set appropriate crop size for the same.