From 5b296fb3dfc397b2741b53c5cc41292a5f14bf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=89=E9=A9=AC?= Date: Sat, 12 Sep 2015 19:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E7=A0=81=E4=BC=98=E5=8C=96=E3=80=81?= =?UTF-8?q?=E6=89=8B=E5=B7=A5=E8=BE=93=E5=85=A5=E6=9D=A1=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj | 6 ++ .../sp_0.imageset/Contents.json | 6 +- .../ProductCheck/ProductCheck.storyboard | 74 +++++++++++++++++++ .../YHB_Prj/Scan/DJInputCodeViewController.h | 17 +++++ .../YHB_Prj/Scan/DJInputCodeViewController.m | 51 +++++++++++++ YHB_Prj/YHB_Prj/Scan/DJScanViewController.h | 8 +- YHB_Prj/YHB_Prj/Scan/DJScanViewController.m | 42 ++++++++--- .../YHB_Prj/shangpinguanli/ShangpinguanliVC.m | 4 - 8 files changed, 183 insertions(+), 25 deletions(-) create mode 100644 YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.h create mode 100644 YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.m diff --git a/YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj b/YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj index edb190a..a565518 100644 --- a/YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj +++ b/YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 5B54BA481B9348FD002098A4 /* DJProductCheckViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B54BA471B9348FD002098A4 /* DJProductCheckViewManager.m */; }; 5BA5AA311B98297400329677 /* DJScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5BA5AA301B98297400329677 /* DJScanViewController.m */; }; 5BA5AA331B98299D00329677 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BA5AA321B98299D00329677 /* AVFoundation.framework */; }; + 5BF62F771BA43ADE0053801E /* DJInputCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5BF62F761BA43ADE0053801E /* DJInputCodeViewController.m */; }; AB2578DC1B8EFBDE0015039A /* GateDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB2578DB1B8EFBDE0015039A /* GateDetailViewController.m */; }; AB2579341B8F02010015039A /* IQNSArray+Sort.m in Sources */ = {isa = PBXBuildFile; fileRef = AB2579121B8F02010015039A /* IQNSArray+Sort.m */; }; AB2579351B8F02010015039A /* IQUITextFieldView+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = AB2579141B8F02010015039A /* IQUITextFieldView+Additions.m */; }; @@ -319,6 +320,8 @@ 5BA5AA2F1B98297400329677 /* DJScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJScanViewController.h; sourceTree = ""; }; 5BA5AA301B98297400329677 /* DJScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJScanViewController.m; sourceTree = ""; }; 5BA5AA321B98299D00329677 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + 5BF62F751BA43ADE0053801E /* DJInputCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJInputCodeViewController.h; sourceTree = ""; }; + 5BF62F761BA43ADE0053801E /* DJInputCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJInputCodeViewController.m; sourceTree = ""; }; AB2578DA1B8EFBDE0015039A /* GateDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GateDetailViewController.h; sourceTree = ""; }; AB2578DB1B8EFBDE0015039A /* GateDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GateDetailViewController.m; sourceTree = ""; }; AB2579111B8F02010015039A /* IQNSArray+Sort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "IQNSArray+Sort.h"; sourceTree = ""; }; @@ -893,6 +896,8 @@ children = ( 5BA5AA2F1B98297400329677 /* DJScanViewController.h */, 5BA5AA301B98297400329677 /* DJScanViewController.m */, + 5BF62F751BA43ADE0053801E /* DJInputCodeViewController.h */, + 5BF62F761BA43ADE0053801E /* DJInputCodeViewController.m */, ); path = Scan; sourceTree = ""; @@ -2023,6 +2028,7 @@ FF3C200B1A2F2B330081D3C7 /* NotifyFactoryObject.m in Sources */, FF2A6C3A1A0F3B59001607AC /* NSData+Base64.m in Sources */, FF5C872D1B83279600F79EC1 /* FirstViewController.m in Sources */, + 5BF62F771BA43ADE0053801E /* DJInputCodeViewController.m in Sources */, FF4DFCF61B856B9600617660 /* ThreadSafeMutableArry.m in Sources */, FF5C86FC1B81B72400F79EC1 /* MASViewAttribute.m in Sources */, FF5C87001B81B72400F79EC1 /* View+MASAdditions.m in Sources */, diff --git a/YHB_Prj/YHB_Prj/Images.xcassets/sp_0.imageset/Contents.json b/YHB_Prj/YHB_Prj/Images.xcassets/sp_0.imageset/Contents.json index 0470b4b..7d3cd6d 100644 --- a/YHB_Prj/YHB_Prj/Images.xcassets/sp_0.imageset/Contents.json +++ b/YHB_Prj/YHB_Prj/Images.xcassets/sp_0.imageset/Contents.json @@ -2,12 +2,12 @@ "images" : [ { "idiom" : "universal", - "scale" : "1x" + "scale" : "1x", + "filename" : "sp_0.png" }, { "idiom" : "universal", - "scale" : "2x", - "filename" : "sp_0.png" + "scale" : "2x" }, { "idiom" : "universal", diff --git a/YHB_Prj/YHB_Prj/ProductCheck/ProductCheck.storyboard b/YHB_Prj/YHB_Prj/ProductCheck/ProductCheck.storyboard index 4a062a8..5eec46b 100644 --- a/YHB_Prj/YHB_Prj/ProductCheck/ProductCheck.storyboard +++ b/YHB_Prj/YHB_Prj/ProductCheck/ProductCheck.storyboard @@ -598,6 +598,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -787,6 +859,7 @@ + @@ -1389,5 +1462,6 @@ + diff --git a/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.h b/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.h new file mode 100644 index 0000000..dbb2e1c --- /dev/null +++ b/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.h @@ -0,0 +1,17 @@ +// +// DJInputCodeViewController.h +// YHB_Prj +// +// Created by yato_kami on 15/9/12. +// Copyright (c) 2015年 striveliu. All rights reserved. +// + +#import "BaseViewController.h" + +typedef void(^successInputHandler)(NSString *codeStr); + +@interface DJInputCodeViewController : BaseViewController + +@property (nonatomic, copy) successInputHandler sHandler; + +@end diff --git a/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.m b/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.m new file mode 100644 index 0000000..1a8f223 --- /dev/null +++ b/YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.m @@ -0,0 +1,51 @@ +// +// DJInputCodeViewController.m +// YHB_Prj +// +// Created by yato_kami on 15/9/12. +// Copyright (c) 2015年 striveliu. All rights reserved. +// + +#import "DJInputCodeViewController.h" + +@interface DJInputCodeViewController () +@property (weak, nonatomic) IBOutlet UITextField *codeTextField; + +@end + +@implementation DJInputCodeViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + [self settitleLabel:@"手工输入条码"]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + [self.codeTextField resignFirstResponder]; +} + +- (IBAction)touchComfirm:(id)sender { + [self.navigationController popViewControllerAnimated:YES]; + [self.codeTextField resignFirstResponder]; + if (self.sHandler) { + self.sHandler(self.codeTextField.text); + } +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/YHB_Prj/YHB_Prj/Scan/DJScanViewController.h b/YHB_Prj/YHB_Prj/Scan/DJScanViewController.h index 21c1fe2..6d9ee6e 100644 --- a/YHB_Prj/YHB_Prj/Scan/DJScanViewController.h +++ b/YHB_Prj/YHB_Prj/Scan/DJScanViewController.h @@ -11,17 +11,13 @@ @protocol DJScanDelegate /** - * 扫描出信息的徽标 + * 成功扫描出了信息 或者用户手动收入了一串信息 * - * @param message 扫描出的信息 + * @param message 扫描出的信息或输入的信息 * */ - (void)scanController:(UIViewController *)vc didScanedAndTransToMessage: (NSString *)message; -/** - * 用户点击了手工输入码 - */ -- (void)needToInputNumberFromScanController:(UIViewController *)vc; @end diff --git a/YHB_Prj/YHB_Prj/Scan/DJScanViewController.m b/YHB_Prj/YHB_Prj/Scan/DJScanViewController.m index ce51e74..5fe3528 100644 --- a/YHB_Prj/YHB_Prj/Scan/DJScanViewController.m +++ b/YHB_Prj/YHB_Prj/Scan/DJScanViewController.m @@ -8,6 +8,8 @@ #import "DJScanViewController.h" #import +#import "DJStoryboadManager.h" +#import "DJInputCodeViewController.h" #define kButtonWidth 180 #define kButtonHeight 40 @@ -18,6 +20,7 @@ @interface DJScanViewController() @property (nonatomic, assign) BOOL isReading; @property (nonatomic, strong) AVCaptureSession * captureSession; @property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer; +@property (nonatomic, assign) CGRect scanRect; @end; @@ -25,10 +28,10 @@ @implementation DJScanViewController - (void)viewDidLoad { [super viewDidLoad]; + [self initailUI]; if (![self startReading]) { [self.navigationController popViewControllerAnimated:YES]; } - [self initailUI]; } @@ -53,10 +56,16 @@ - (void)initailUI { } - (void)inputNum: (UIButton *)sender { - if ([self.delegate respondsToSelector:@selector(scanController:didScanedAndTransToMessage:)]) { - [self.navigationController popViewControllerAnimated:YES]; - [self.delegate needToInputNumberFromScanController:self]; - } + DJInputCodeViewController *vc = (DJInputCodeViewController *)[[DJStoryboadManager sharedInstance] viewControllerWithName:@"DJInputCodeViewController"]; + __weak typeof(self) weakself = self; + [vc setSHandler:^(NSString *codeStr){ + if (codeStr.length) { + if ([weakself.delegate respondsToSelector:@selector(scanController:didScanedAndTransToMessage:)]) { + [weakself.delegate scanController:weakself didScanedAndTransToMessage:codeStr]; + } + } + }]; + [self.navigationController pushViewController:vc animated:YES]; } - (BOOL)startReading { @@ -81,14 +90,20 @@ - (BOOL)startReading { AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init]; [_captureSession addOutput:captureMetadataOutput]; - - - // [captureMetadataOutput setRectOfInterest:CGRectMake(0.5, 0.5, 0.5, 0.5)]; + + NSLog(@"%@ %@",[NSValue valueWithCGRect:self.view.frame],[NSValue valueWithCGRect:self.scanRect]); + //优化 + CGFloat x = self.scanRect.origin.x / self.view.width; + + CGFloat y = (self.scanRect.origin.y) / self.view.height; + CGFloat width = self.scanRect.size.width / self.view.width; + CGFloat height = self.scanRect.size.height / self.view.height; + [captureMetadataOutput setRectOfInterest:CGRectMake(y, x, height, width)]; [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; - [captureMetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode,AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code]]; + [captureMetadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code]]; _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession]; [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; @@ -103,10 +118,11 @@ - (BOOL)startReading { - (void)addShape { CGFloat x = (kMainScreenWidth - kScanWidth) / 2.; CGFloat y = 40 + 40; - + self.scanRect = CGRectMake(x, y, kScanWidth, kScanWidth); + CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, nil, self.view.bounds); - CGPathAddRect(path, nil, CGRectMake(x, y, kScanWidth, kScanWidth)); + CGPathAddRect(path, nil, self.scanRect); CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.strokeColor = [UIColor whiteColor].CGColor; @@ -118,6 +134,8 @@ - (void)addShape { shapeLayer.path = path; [self.view.layer addSublayer:shapeLayer]; + + CGPathRelease(path); } @@ -140,8 +158,8 @@ -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:( NSLog(@"扫描到的信息%@",metadataObj.stringValue); if ([self.delegate respondsToSelector:@selector(scanController:didScanedAndTransToMessage:)]) { [self stopReading]; - [self.delegate scanController:self didScanedAndTransToMessage:metadataObj.stringValue]; [self.navigationController popViewControllerAnimated:YES]; + [self.delegate scanController:self didScanedAndTransToMessage:metadataObj.stringValue]; } } } diff --git a/YHB_Prj/YHB_Prj/shangpinguanli/ShangpinguanliVC.m b/YHB_Prj/YHB_Prj/shangpinguanli/ShangpinguanliVC.m index ccffc7c..5edff9a 100644 --- a/YHB_Prj/YHB_Prj/shangpinguanli/ShangpinguanliVC.m +++ b/YHB_Prj/YHB_Prj/shangpinguanli/ShangpinguanliVC.m @@ -104,10 +104,6 @@ - (void)scanController:(UIViewController *)vc didScanedAndTransToMessage: (NSStr [self.navigationController setViewControllers:viewControllers animated:YES]; } -- (void)needToInputNumberFromScanController:(UIViewController *)vc -{ - -} #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView