Focus animation is a complete custom animation that you must create yourself. I currently have the same problem as you: I want to show the rectangle as feedback for the user after he clicked on the preview layer.
The first thing you want to do is implement focus snap, possibly where you trigger the preview layer:
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToFocus:)]; [tapGR setNumberOfTapsRequired:1]; [tapGR setNumberOfTouchesRequired:1]; [self.captureVideoPreviewView addGestureRecognizer:tapGR];
Now implement the snap to focus method itself:
-(void)tapToFocus:(UITapGestureRecognizer *)singleTap{ CGPoint touchPoint = [singleTap locationInView:self.captureVideoPreviewView]; CGPoint convertedPoint = [self.captureVideoPreviewLayer captureDevicePointOfInterestForPoint:touchPoint]; AVCaptureDevice *currentDevice = currentInput.device; if([currentDevice isFocusPointOfInterestSupported] && [currentDevice isFocusModeSupported:AVCaptureFocusModeAutoFocus]){ NSError *error = nil; [currentDevice lockForConfiguration:&error]; if(!error){ [currentDevice setFocusPointOfInterest:convertedPoint]; [currentDevice setFocusMode:AVCaptureFocusModeAutoFocus]; [currentDevice unlockForConfiguration]; } } }
The last thing that I have not yet implemented myself is to add a focusing animation to the preview level, or rather, to the view controller that holds the preview layer. I believe that this can be done in tapToFocus :. There you already have a touch point. Just add an animated image or other representation that has a touch position as its center. After the animation is finished, take an image.
xxtesaxx
source share