Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The focus animation is a complete custom animation which you have to create by your own. I am currently having exact the same problem like you: I want to show a rectangle as a feedback for the user after he tapped the preview layer.</p> <p>The first thing you want to do is implementing the tap-to-focus, probably where you initiate the preview layer:</p> <pre><code>UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToFocus:)]; [tapGR setNumberOfTapsRequired:1]; [tapGR setNumberOfTouchesRequired:1]; [self.captureVideoPreviewView addGestureRecognizer:tapGR]; </code></pre> <p>Now implement the tap-to-focus method itself:</p> <pre><code>-(void)tapToFocus:(UITapGestureRecognizer *)singleTap{ CGPoint touchPoint = [singleTap locationInView:self.captureVideoPreviewView]; CGPoint convertedPoint = [self.captureVideoPreviewLayer captureDevicePointOfInterestForPoint:touchPoint]; AVCaptureDevice *currentDevice = currentInput.device; if([currentDevice isFocusPointOfInterestSupported] &amp;&amp; [currentDevice isFocusModeSupported:AVCaptureFocusModeAutoFocus]){ NSError *error = nil; [currentDevice lockForConfiguration:&amp;error]; if(!error){ [currentDevice setFocusPointOfInterest:convertedPoint]; [currentDevice setFocusMode:AVCaptureFocusModeAutoFocus]; [currentDevice unlockForConfiguration]; } } } </code></pre> <p>The last thing, which i haven't implemented by myself yet, is to add the focusing animation to the preview layer or rather the view controller which is holding the preview layer. I believe that could be done in tapToFocus:. There you already have the touch point. Simply add a animated image view or some other view which has the touch position as its center. After the animation has finished, remove the image view.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload