From 694aecb78cb82797f038e44e3187bb6b5d5a1a60 Mon Sep 17 00:00:00 2001 From: Yannick Winters Date: Tue, 16 Aug 2016 16:20:24 +0200 Subject: [PATCH] Added function to zoom from code --- LLSimpleCamera/LLSimpleCamera.h | 11 +++++++++++ LLSimpleCamera/LLSimpleCamera.m | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/LLSimpleCamera/LLSimpleCamera.h b/LLSimpleCamera/LLSimpleCamera.h index 4e9f9f5..5e438a9 100644 --- a/LLSimpleCamera/LLSimpleCamera.h +++ b/LLSimpleCamera/LLSimpleCamera.h @@ -215,6 +215,13 @@ typedef enum : NSUInteger { */ - (void)alterFocusBox:(CALayer *)layer animation:(CAAnimation *)animation; +/** + * Function to zoom the camera from code + * + * @param factor from 0.0 to 1.0 + */ +- (void) scaleToFactor:(CGFloat)factor; + /** * Checks is the front camera is available. */ @@ -224,4 +231,8 @@ typedef enum : NSUInteger { * Checks is the rear camera is available. */ + (BOOL)isRearCameraAvailable; + + + + @end diff --git a/LLSimpleCamera/LLSimpleCamera.m b/LLSimpleCamera/LLSimpleCamera.m index db75c9f..28600c9 100644 --- a/LLSimpleCamera/LLSimpleCamera.m +++ b/LLSimpleCamera/LLSimpleCamera.m @@ -150,6 +150,18 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer } } +#pragma mark - Zooming programmatically +- (void) scaleToFactor:(CGFloat)factor +{ + NSError *error = nil; + if ([self.videoCaptureDevice lockForConfiguration:&error]) + { + [self.videoCaptureDevice rampToVideoZoomFactor:factor withRate:10]; + + [self.videoCaptureDevice unlockForConfiguration]; + } +} + #pragma mark - Camera - (void)attachToViewController:(UIViewController *)vc withFrame:(CGRect)frame