I have implemented the code below to enable tap to focus camera. It is working fine with the back camera but is fails when using the front camera because of
_videoCamera.inputCamera.isFocusPointOfInterestSupported
being false.
GOT FALSE why ? please help me.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
if([_videoCamera.inputCamera isFocusPointOfInterestSupported]&&[_videoCamera.inputCamera isFocusModeSupported:AVCaptureFocusModeAutoFocus])
{
if([_videoCamera.inputCamera lockForConfiguration :nil])
{
[_videoCamera.inputCamera setFocusPointOfInterest :touchPoint];
[_videoCamera.inputCamera setFocusMode :AVCaptureFocusModeLocked];
if([_videoCamera.inputCamera isExposurePointOfInterestSupported])
{ CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
double focus_x = touchPoint.x/screenWidth;
double focus_y = touchPoint.y/screenHeight;
[_videoCamera.inputCamera setExposurePointOfInterest:CGPointMake(focus_x,focus_y)];
[_videoCamera.inputCamera setFocusMode:AVCaptureFocusModeAutoFocus];
if ([_videoCamera.inputCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[_videoCamera.inputCamera setExposureMode:AVCaptureExposureModeAutoExpose];
}
}
[_videoCamera.inputCamera unlockForConfiguration];
}
}
}
The front-facing camera is fixed focus. No auto-focus, no focus on point of interest. This is exactly what iOS tells you by returning NO
when you call isFocusPointOfInterestSupported
.