Adding UIPinchGestureRecognizer to UIImagePickerController

406 views Asked by At

I'm trying to add UIPinchGestureRecognizer to UIImagePickerController to zoom in/out front camera but were not able to call method inside UIPinchGestureRecognizer (handlePinchWithGestureRecognizer). I didn't get any error but also didn't get any interaction.

Here is the code I'm using in viewDidAppear:

_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
_imagePicker.allowsEditing = YES;
_imagePicker.showsCameraControls = NO;
_imagePicker.navigationBarHidden = YES;
_imagePicker.view.userInteractionEnabled = YES;
_imagePicker.view.multipleTouchEnabled = YES;
_imagePicker.delegate = self;

 UIPinchGestureRecognizer *pinchGestureRecognizer = pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchWithGestureRecognizer:)];


[_imagePicker.view addGestureRecognizer:pinchGestureRecognizer];

[self presentViewController:_imagePicker animated:NO completion:nil];
1

There are 1 answers

0
Pacu On BEST ANSWER

First of all I wouldn't add gesture recognizers to UIKit View Controllers' views that are not meant to be subclassed. You don't know for sure what's going on in there, and how your recognizer may interfere with the view's standard features.

Secondly, I tried to zoom the front camera on my iPhone and it's not possible to do so.

If you want to get video from the front camera and zoom it you will have to implement your own Controller that takes a video session from the front camera and do the transformations to do the zooming, etc.