Skip to content

Instantly share code, notes, and snippets.

@wanewang
Created March 14, 2015 12:58
Show Gist options
  • Save wanewang/3d5ac4b2fef72a92e07c to your computer and use it in GitHub Desktop.
Save wanewang/3d5ac4b2fef72a92e07c to your computer and use it in GitHub Desktop.
AVCaptureVideoPreviewLayer Zoomin
- (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