IPhone camera focus

I used the code below to focus the iphone camera. But that does not work. I take this code from Apple's AVCam sample code. Am I doing something wrong? Is there any way to detect if the iPhone has done the trick?

-(void) focusAtPoint:(CGPoint)point { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];; if (device != nil) { if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) { NSError *error; if ([device lockForConfiguration:&error]) { [device setFocusPointOfInterest:point]; [device setFocusMode:AVCaptureFocusModeAutoFocus]; [device unlockForConfiguration]; } else { NSLog(@"Error in Focus Mode"); } } } } 
+3
source share
1 answer

The point for [AVCaptureDevice setFocusPointOfInterest:] does not coincide with the touch point of the view, but a point between 0.0 and 1.1 (see documents). So you should do:

 CGPoint point = [touch locationInView:self.cameraView]; point.x /= self.cameraView.frame.size.width; point.y /= self.cameraView.frame.size.height; [self focusAtPoint:point]; 
+7
source

All Articles