Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
CEAF7A661A16A31600991CF8 /* QRCodeReaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = CEAF7A651A16A31600991CF8 /* QRCodeReaderView.m */; };
CEAF7A691A16B05400991CF8 /* QRCameraSwitchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = CEAF7A681A16B05400991CF8 /* QRCameraSwitchButton.m */; };
CEF6D1641BE7B2B0006D575D /* QRToggleTorchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF6D1631BE7B2B0006D575D /* QRToggleTorchButton.m */; };
D424A6111CBBB0F90076F44D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D424A60C1CBBB0F90076F44D /* [email protected] */; };
D424A6121CBBB0F90076F44D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D424A60D1CBBB0F90076F44D /* [email protected] */; };
D424A6131CBBB0F90076F44D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D424A60E1CBBB0F90076F44D /* [email protected] */; };
D424A6141CBBB0F90076F44D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D424A60F1CBBB0F90076F44D /* [email protected] */; };
D424A6151CBBB0F90076F44D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D424A6101CBBB0F90076F44D /* [email protected] */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -55,6 +60,11 @@
CEAF7A681A16B05400991CF8 /* QRCameraSwitchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRCameraSwitchButton.m; sourceTree = "<group>"; };
CEF6D1621BE7B2B0006D575D /* QRToggleTorchButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRToggleTorchButton.h; sourceTree = "<group>"; };
CEF6D1631BE7B2B0006D575D /* QRToggleTorchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRToggleTorchButton.m; sourceTree = "<group>"; };
D424A60C1CBBB0F90076F44D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
D424A60D1CBBB0F90076F44D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
D424A60E1CBBB0F90076F44D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
D424A60F1CBBB0F90076F44D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
D424A6101CBBB0F90076F44D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -137,6 +147,7 @@
CE29603E1987F140008FA93B /* QRCodeReaderViewController */ = {
isa = PBXGroup;
children = (
D424A60B1CBBB0F90076F44D /* Resources */,
CE29603F1987F140008FA93B /* QRCodeReaderDelegate.h */,
CE2960401987F140008FA93B /* QRCodeReaderViewController.h */,
CE2960411987F140008FA93B /* QRCodeReaderViewController.m */,
Expand All @@ -153,6 +164,18 @@
path = ../QRCodeReaderViewController;
sourceTree = "<group>";
};
D424A60B1CBBB0F90076F44D /* Resources */ = {
isa = PBXGroup;
children = (
D424A60C1CBBB0F90076F44D /* [email protected] */,
D424A60D1CBBB0F90076F44D /* [email protected] */,
D424A60E1CBBB0F90076F44D /* [email protected] */,
D424A60F1CBBB0F90076F44D /* [email protected] */,
D424A6101CBBB0F90076F44D /* [email protected] */,
);
path = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -202,7 +225,7 @@
TargetAttributes = {
CE2960171987F124008FA93B = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = 5SJ773RP6R;
DevelopmentTeam = 84LY8T43ZV;
};
CE29602D1987F124008FA93B = {
CreatedOnToolsVersion = 6.0;
Expand Down Expand Up @@ -234,6 +257,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D424A6151CBBB0F90076F44D /* [email protected] in Resources */,
D424A6111CBBB0F90076F44D /* [email protected] in Resources */,
D424A6131CBBB0F90076F44D /* [email protected] in Resources */,
D424A6141CBBB0F90076F44D /* [email protected] in Resources */,
D424A6121CBBB0F90076F44D /* [email protected] in Resources */,
CE2960271987F124008FA93B /* Main.storyboard in Resources */,
CE2960291987F124008FA93B /* Images.xcassets in Resources */,
);
Expand Down Expand Up @@ -379,13 +407,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_IDENTITY = "iPhone Developer: Bo Liu (C27S66H283)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Bo Liu (C27S66H283)";
INFOPLIST_FILE = QRCodeReaderViewControllerExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_BUNDLE_IDENTIFIER = com.tgnet.ywq;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE = "4290ec7a-f199-4988-8b69-9ee1492b3634";
};
name = Debug;
};
Expand All @@ -394,13 +422,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_IDENTITY = "iPhone Developer: Bo Liu (C27S66H283)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Bo Liu (C27S66H283)";
INFOPLIST_FILE = QRCodeReaderViewControllerExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_BUNDLE_IDENTIFIER = com.tgnet.ywq;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE = "4290ec7a-f199-4988-8b69-9ee1492b3634";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -19,7 +19,6 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kct-zV-dJD">
<rect key="frame" x="223" y="225" width="155" height="150"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="155" id="4hI-l3-fwn"/>
<constraint firstAttribute="height" constant="150" id="qAa-36-Hfs"/>
Expand All @@ -32,7 +31,6 @@
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="kct-zV-dJD" secondAttribute="centerY" id="9JB-hP-LAl"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -44,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
132 changes: 102 additions & 30 deletions QRCodeReaderViewController/QRCodeReaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,32 @@

#import "QRCodeReaderView.h"

#define SCAN_QRCODE_TEXT_TITLE @"扫一扫"

#define SCAN_QRCODE_BGCOLOR [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]

#define SCAN_QRCODE_IMG_LEFT_UP @"center_qrcode_leftup_img"
#define SCAN_QRCODE_IMG_RIGHT_UP @"center_qrcode_rightup_img"
#define SCAN_QRCODE_IMG_LEFT_DOWN @"center_qrcode_leftdown_img"
#define SCAN_QRCODE_IMG_RIGHT_DOWN @"center_qrcode_rightdown_img"

#define SCAN_QRCODE_IMG_LINE @"center_qrcode_line_img"

@interface QRCodeReaderView ()
@property (nonatomic, strong) CAShapeLayer *overlay;

@property (weak, nonatomic) UIView *topViewBG;
@property (weak, nonatomic) UIView *leftViewBG;
@property (weak, nonatomic) UIView *rightViewBG;
@property (weak, nonatomic) UIView *bottomViewBG;

@property (weak, nonatomic) UIImageView *leftUpImageView;
@property (weak, nonatomic) UIImageView *leftDownImageView;
@property (weak, nonatomic) UIImageView *rightUpImageView;
@property (weak, nonatomic) UIImageView *rightDownImageView;

@property (weak, nonatomic) UIImageView *lineImageView;

@property (weak, nonatomic) UILabel *tipLabel;

@end

Expand All @@ -36,45 +60,93 @@ @implementation QRCodeReaderView
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[self addOverlay];
[self setupSubViews];
}

return self;
}

- (void)drawRect:(CGRect)rect
{
CGRect innerRect = CGRectInset(rect, 50, 50);

CGFloat minSize = MIN(innerRect.size.width, innerRect.size.height);
if (innerRect.size.width != minSize) {
innerRect.origin.x += (innerRect.size.width - minSize) / 2;
innerRect.size.width = minSize;
}
else if (innerRect.size.height != minSize) {
innerRect.origin.y += (innerRect.size.height - minSize) / 2;
innerRect.size.height = minSize;
}

CGRect offsetRect = CGRectOffset(innerRect, 0, 15);
- (void)setupSubViews{

self.topViewBG = [self createViewBG];
[self addSubview:self.topViewBG];

self.leftViewBG = [self createViewBG];
[self addSubview:self.leftViewBG];

self.rightViewBG = [self createViewBG];
[self addSubview:self.rightViewBG];

self.bottomViewBG = [self createViewBG];
[self addSubview:self.bottomViewBG];

self.leftUpImageView = [self createImageViewWithImageName:SCAN_QRCODE_IMG_LEFT_UP];
[self addSubview:self.leftUpImageView];

self.leftDownImageView = [self createImageViewWithImageName:SCAN_QRCODE_IMG_LEFT_DOWN];
[self addSubview:self.leftDownImageView];

self.rightUpImageView = [self createImageViewWithImageName:SCAN_QRCODE_IMG_RIGHT_UP];
[self addSubview:self.rightUpImageView];

self.rightDownImageView = [self createImageViewWithImageName:SCAN_QRCODE_IMG_RIGHT_DOWN];
[self addSubview:self.rightDownImageView];

self.lineImageView = [self createImageViewWithImageName:SCAN_QRCODE_IMG_LINE];
[self addSubview:self.lineImageView];

UILabel *tipLabel = [[UILabel alloc] init];
[tipLabel setNumberOfLines:0];
[tipLabel setText:@"将二维码图案放在取景框内,即可自动扫描"];
[tipLabel setTextColor:[UIColor whiteColor]];
[tipLabel setBackgroundColor:[UIColor clearColor]];
[tipLabel setTextAlignment:NSTextAlignmentCenter];
[tipLabel setFont:[UIFont systemFontOfSize:14]];
self.tipLabel = tipLabel;
[self addSubview:self.tipLabel];

}

- (UIView *)createViewBG{
UIView *viewBG = [[UIView alloc] init];
[viewBG setBackgroundColor:SCAN_QRCODE_BGCOLOR];
return viewBG;
}

_overlay.path = [UIBezierPath bezierPathWithRoundedRect:offsetRect cornerRadius:5].CGPath;
- (UIImageView *)createImageViewWithImageName:(NSString *)imageName{
UIImageView *imgView = [[UIImageView alloc] init];
[imgView setImage:[UIImage imageNamed:imageName]];
return imgView;
}

#pragma mark - Private Methods
- (void)layoutSubviews{
[super layoutSubviews];

CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;

self.topViewBG.frame = CGRectMake(40, 0, width-40, 40);
self.leftViewBG.frame = CGRectMake(0, 0, 40, width);
self.rightViewBG.frame = CGRectMake(width-40, 40, 40, width);
self.bottomViewBG.frame = CGRectMake(40, width - 40, width - 80, height- width + 40);

self.leftUpImageView.frame = CGRectMake(37, 37, 30, 30);
self.leftDownImageView.frame = CGRectMake(37, width - 67, 30, 30);
self.rightUpImageView.frame = CGRectMake(width - 67, 37, 30, 30);
self.rightDownImageView.frame = CGRectMake(width - 67, width - 67, 30, 30);

self.lineImageView.frame = CGRectMake(40, 40, width - 80, 2);
[UIView animateWithDuration:3.0 delay:0 options:UIViewAnimationOptionRepeat animations:^{
[self.lineImageView setFrame:CGRectMake(40, width - 45, width - 80, 2)];
} completion:^(BOOL finished) {

}];


self.tipLabel.frame = CGRectMake(10, width-25, width-20, 60);

- (void)addOverlay
{
_overlay = [[CAShapeLayer alloc] init];
_overlay.backgroundColor = [UIColor clearColor].CGColor;
_overlay.fillColor = [UIColor clearColor].CGColor;
_overlay.strokeColor = [UIColor whiteColor].CGColor;
_overlay.lineWidth = 3;
_overlay.lineDashPattern = @[@7.0, @7.0];
_overlay.lineDashPhase = 0;

[self.layer addSublayer:_overlay];

}


@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.