Skip to content

Commit

Permalink
扫码优化、手工输入条码逻辑增加
Browse files Browse the repository at this point in the history
  • Loading branch information
有马 committed Sep 12, 2015
1 parent 468089c commit 5b296fb
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 25 deletions.
6 changes: 6 additions & 0 deletions YHB_Prj/YHB_Prj.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -319,6 +320,8 @@
5BA5AA2F1B98297400329677 /* DJScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DJScanViewController.h; sourceTree = "<group>"; };
5BA5AA301B98297400329677 /* DJScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJScanViewController.m; sourceTree = "<group>"; };
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 = "<group>"; };
5BF62F761BA43ADE0053801E /* DJInputCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DJInputCodeViewController.m; sourceTree = "<group>"; };
AB2578DA1B8EFBDE0015039A /* GateDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GateDetailViewController.h; sourceTree = "<group>"; };
AB2578DB1B8EFBDE0015039A /* GateDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GateDetailViewController.m; sourceTree = "<group>"; };
AB2579111B8F02010015039A /* IQNSArray+Sort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "IQNSArray+Sort.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -893,6 +896,8 @@
children = (
5BA5AA2F1B98297400329677 /* DJScanViewController.h */,
5BA5AA301B98297400329677 /* DJScanViewController.m */,
5BF62F751BA43ADE0053801E /* DJInputCodeViewController.h */,
5BF62F761BA43ADE0053801E /* DJInputCodeViewController.m */,
);
path = Scan;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
6 changes: 3 additions & 3 deletions YHB_Prj/YHB_Prj/Images.xcassets/sp_0.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
74 changes: 74 additions & 0 deletions YHB_Prj/YHB_Prj/ProductCheck/ProductCheck.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,78 @@
</objects>
<point key="canvasLocation" x="503" y="312"/>
</scene>
<!--Input Code View Controller-->
<scene sceneID="Sri-ak-qeD">
<objects>
<viewController storyboardIdentifier="DJInputCodeViewController" id="bLB-Mn-JcK" customClass="DJInputCodeViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Dyn-6L-gTz"/>
<viewControllerLayoutGuide type="bottom" id="frb-CV-6ja"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="QIt-L1-YC8">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="条码:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rDs-ou-BXm">
<rect key="frame" x="39" y="41.5" width="34.5" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sp_0" translatesAutoresizingMaskIntoConstraints="NO" id="yNZ-cn-9cJ">
<rect key="frame" x="16" y="43" width="15" height="15"/>
<constraints>
<constraint firstAttribute="width" constant="15" id="HJS-T9-olk"/>
<constraint firstAttribute="height" constant="15" id="TF5-iI-aeE"/>
</constraints>
</imageView>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="请输入条码" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="IPG-jU-0AS">
<rect key="frame" x="81" y="36" width="502.5" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad" returnKeyType="go"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AmG-ex-Qr4">
<rect key="frame" x="200" y="138" width="200" height="40"/>
<color key="backgroundColor" red="0.99215686270000003" green="0.52156862749999999" blue="0.039215686270000001" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="5UQ-h6-SIa"/>
<constraint firstAttribute="height" constant="40" id="ZYB-Ov-nf1"/>
</constraints>
<state key="normal" title="确定">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="5"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="touchComfirm:" destination="bLB-Mn-JcK" eventType="touchUpInside" id="kAb-ss-nIG"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="yNZ-cn-9cJ" firstAttribute="leading" secondItem="QIt-L1-YC8" secondAttribute="leadingMargin" id="1n2-bc-qq5"/>
<constraint firstItem="AmG-ex-Qr4" firstAttribute="top" secondItem="IPG-jU-0AS" secondAttribute="bottom" constant="72" id="D3u-oz-TSz"/>
<constraint firstItem="rDs-ou-BXm" firstAttribute="leading" secondItem="yNZ-cn-9cJ" secondAttribute="trailing" constant="8" id="Fmu-PP-bKe"/>
<constraint firstItem="rDs-ou-BXm" firstAttribute="centerY" secondItem="yNZ-cn-9cJ" secondAttribute="centerY" id="GTH-En-lSq"/>
<constraint firstAttribute="centerX" secondItem="AmG-ex-Qr4" secondAttribute="centerX" id="ZnK-HR-5Ak"/>
<constraint firstItem="rDs-ou-BXm" firstAttribute="centerY" secondItem="IPG-jU-0AS" secondAttribute="centerY" constant="-0.5" id="olz-ca-YzG"/>
<constraint firstItem="IPG-jU-0AS" firstAttribute="leading" secondItem="rDs-ou-BXm" secondAttribute="trailing" constant="8" id="puS-cu-40D"/>
<constraint firstItem="yNZ-cn-9cJ" firstAttribute="top" secondItem="Dyn-6L-gTz" secondAttribute="bottom" constant="23" id="u5P-zg-rNO"/>
<constraint firstItem="IPG-jU-0AS" firstAttribute="trailing" secondItem="QIt-L1-YC8" secondAttribute="trailingMargin" id="u78-sj-YUj"/>
</constraints>
</view>
<connections>
<outlet property="codeTextField" destination="IPG-jU-0AS" id="jTJ-se-3EC"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Prc-Gc-8VE" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="489" y="979"/>
</scene>
<!--Product Check ListVC-->
<scene sceneID="1uh-AS-rTl">
<objects>
Expand Down Expand Up @@ -787,6 +859,7 @@
</state>
</button>
<barButtonItem key="rightBarButtonItem" image="menicon_4" id="rev-nT-nTC">
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<action selector="touchDateItem:" destination="DyI-k4-XyD" id="FeQ-T5-l15"/>
</connections>
Expand Down Expand Up @@ -1389,5 +1462,6 @@
<resources>
<image name="icon_2" width="9" height="8"/>
<image name="menicon_4" width="32" height="32"/>
<image name="sp_0" width="18" height="16"/>
</resources>
</document>
17 changes: 17 additions & 0 deletions YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.h
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions YHB_Prj/YHB_Prj/Scan/DJInputCodeViewController.m
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions YHB_Prj/YHB_Prj/Scan/DJScanViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
@protocol DJScanDelegate<NSObject>

/**
* 扫描出信息的徽标
* 成功扫描出了信息 或者用户手动收入了一串信息
*
* @param message 扫描出的信息
* @param message 扫描出的信息或输入的信息
*
*/
- (void)scanController:(UIViewController *)vc didScanedAndTransToMessage: (NSString *)message;

/**
* 用户点击了手工输入码
*/
- (void)needToInputNumberFromScanController:(UIViewController *)vc;

@end

Expand Down
42 changes: 30 additions & 12 deletions YHB_Prj/YHB_Prj/Scan/DJScanViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "DJScanViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "DJStoryboadManager.h"
#import "DJInputCodeViewController.h"

#define kButtonWidth 180
#define kButtonHeight 40
Expand All @@ -18,17 +20,18 @@ @interface DJScanViewController()<AVCaptureMetadataOutputObjectsDelegate>
@property (nonatomic, assign) BOOL isReading;
@property (nonatomic, strong) AVCaptureSession * captureSession;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer;
@property (nonatomic, assign) CGRect scanRect;

@end;

@implementation DJScanViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self initailUI];
if (![self startReading]) {
[self.navigationController popViewControllerAnimated:YES];
}
[self initailUI];
}


Expand All @@ -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 {
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -118,6 +134,8 @@ - (void)addShape {
shapeLayer.path = path;

[self.view.layer addSublayer:shapeLayer];



CGPathRelease(path);
}
Expand All @@ -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];
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions YHB_Prj/YHB_Prj/shangpinguanli/ShangpinguanliVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b296fb

Please sign in to comment.