Created
March 14, 2015 12:58
-
-
Save wanewang/3d5ac4b2fef72a92e07c to your computer and use it in GitHub Desktop.
AVCaptureVideoPreviewLayer Zoomin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer { | |
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) { | |
self.lastScale = self.effectiveScale; | |
} | |
self.effectiveScale = self.lastScale * gestureRecognizer.scale; | |
if (self.effectiveScale < 1.0) { | |
self.effectiveScale = 1.0; | |
} | |
CGFloat maxScaleAndCropFactor = [[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor]; | |
if (self.effectiveScale > maxScaleAndCropFactor) { | |
self.effectiveScale = maxScaleAndCropFactor; | |
} | |
[CATransaction begin]; | |
[CATransaction setAnimationDuration:.025]; | |
[self.previewLayer setAffineTransform:CGAffineTransformMakeScale(self.effectiveScale, self.effectiveScale)]; | |
[CATransaction commit]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment