From b3547de4a251bb03a47974dc34e93e1b17965445 Mon Sep 17 00:00:00 2001 From: shabake <45329453@qq.com> Date: Wed, 10 Apr 2019 16:18:01 +0800 Subject: [PATCH] updata code --- GHCameraModule/GHCameraModule.m | 44 +++++++++++++++++++++---- GHCustom/GHCameraModuleViewController.m | 2 +- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/GHCameraModule/GHCameraModule.m b/GHCameraModule/GHCameraModule.m index 88f4c21..a02e6a8 100644 --- a/GHCameraModule/GHCameraModule.m +++ b/GHCameraModule/GHCameraModule.m @@ -30,6 +30,7 @@ @interface GHCameraModule() 0) { AVMetadataMachineReadableCodeObject *metadataObject = [metadataObjects objectAtIndex :0]; + NSString *string = metadataObject.stringValue; + self.string = string; + NSArray *array = metadataObject.corners; + NSLog(@"array%@",array); + CGPoint point = CGPointZero; + int index = 0; + CFDictionaryRef dict = (__bridge CFDictionaryRef)(array[index++]); + CGPointMakeWithDictionaryRepresentation(dict, &point); + CGPoint point2 = CGPointZero; + CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)array[2], &point2); + CGFloat scace = 100 /(point2.x-point.x); + NSLog(@"scacescacescace%f",scace); + [self setVideoScale:scace]; + } +} + +- (void)setVideoScale:(CGFloat)scale{ + + [self.input.device lockForConfiguration:nil]; + //获取放大最大倍数 + AVCaptureConnection *videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; + CGFloat maxScaleAndCropFactor = ([[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor])/16; + + scale = 1.4; + videoConnection.videoScaleAndCropFactor = scale; + [CATransaction begin]; + [CATransaction setAnimationDuration:0.25]; + [self.previewLayer setAffineTransform:CGAffineTransformMakeScale(scale, scale)]; + videoConnection.videoScaleAndCropFactor = scale; + [CATransaction commit]; + [CATransaction setCompletionBlock:^{ [self.session stopRunning]; + [self.input.device unlockForConfiguration]; - NSString *string = metadataObject.stringValue; - if (string.length) { - NSString *resultString = metadataObject.stringValue; + if (self.string.length) { if (self.cameraModuleCodeBlock) { - self.cameraModuleCodeBlock(resultString); + self.cameraModuleCodeBlock(self.string); } if (self.delegate && [self.delegate respondsToSelector:@selector(cameraModule:info:resultString:)]) { - [self.delegate cameraModule:self info:nil resultString:resultString]; + [self.delegate cameraModule:self info:nil resultString:self.string]; } } - } + }]; } - - (void)screenshot { AVCaptureConnection * videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; if (!videoConnection) { diff --git a/GHCustom/GHCameraModuleViewController.m b/GHCustom/GHCameraModuleViewController.m index 8317a86..0221e63 100644 --- a/GHCustom/GHCameraModuleViewController.m +++ b/GHCustom/GHCameraModuleViewController.m @@ -227,7 +227,7 @@ - (void)cameraModule:(GHCameraModule *)cameraModule info:(NSDictionary *)info re - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0) { - [self.cameraModule start]; +// [self.cameraModule start]; } #pragma mark - 懒加载