diff --git a/Example/QRCodeReaderViewControllerExample.xcodeproj/project.pbxproj b/Example/QRCodeReaderViewControllerExample.xcodeproj/project.pbxproj index 46067ad..34231e6 100644 --- a/Example/QRCodeReaderViewControllerExample.xcodeproj/project.pbxproj +++ b/Example/QRCodeReaderViewControllerExample.xcodeproj/project.pbxproj @@ -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 /* center_qrcode_leftdown_img@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D424A60C1CBBB0F90076F44D /* center_qrcode_leftdown_img@2x.png */; }; + D424A6121CBBB0F90076F44D /* center_qrcode_leftup_img@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D424A60D1CBBB0F90076F44D /* center_qrcode_leftup_img@2x.png */; }; + D424A6131CBBB0F90076F44D /* center_qrcode_line_img@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D424A60E1CBBB0F90076F44D /* center_qrcode_line_img@2x.png */; }; + D424A6141CBBB0F90076F44D /* center_qrcode_rightdown_img@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D424A60F1CBBB0F90076F44D /* center_qrcode_rightdown_img@2x.png */; }; + D424A6151CBBB0F90076F44D /* center_qrcode_rightup_img@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D424A6101CBBB0F90076F44D /* center_qrcode_rightup_img@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -55,6 +60,11 @@ CEAF7A681A16B05400991CF8 /* QRCameraSwitchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRCameraSwitchButton.m; sourceTree = ""; }; CEF6D1621BE7B2B0006D575D /* QRToggleTorchButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRToggleTorchButton.h; sourceTree = ""; }; CEF6D1631BE7B2B0006D575D /* QRToggleTorchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRToggleTorchButton.m; sourceTree = ""; }; + D424A60C1CBBB0F90076F44D /* center_qrcode_leftdown_img@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "center_qrcode_leftdown_img@2x.png"; sourceTree = ""; }; + D424A60D1CBBB0F90076F44D /* center_qrcode_leftup_img@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "center_qrcode_leftup_img@2x.png"; sourceTree = ""; }; + D424A60E1CBBB0F90076F44D /* center_qrcode_line_img@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "center_qrcode_line_img@2x.png"; sourceTree = ""; }; + D424A60F1CBBB0F90076F44D /* center_qrcode_rightdown_img@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "center_qrcode_rightdown_img@2x.png"; sourceTree = ""; }; + D424A6101CBBB0F90076F44D /* center_qrcode_rightup_img@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "center_qrcode_rightup_img@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -137,6 +147,7 @@ CE29603E1987F140008FA93B /* QRCodeReaderViewController */ = { isa = PBXGroup; children = ( + D424A60B1CBBB0F90076F44D /* Resources */, CE29603F1987F140008FA93B /* QRCodeReaderDelegate.h */, CE2960401987F140008FA93B /* QRCodeReaderViewController.h */, CE2960411987F140008FA93B /* QRCodeReaderViewController.m */, @@ -153,6 +164,18 @@ path = ../QRCodeReaderViewController; sourceTree = ""; }; + D424A60B1CBBB0F90076F44D /* Resources */ = { + isa = PBXGroup; + children = ( + D424A60C1CBBB0F90076F44D /* center_qrcode_leftdown_img@2x.png */, + D424A60D1CBBB0F90076F44D /* center_qrcode_leftup_img@2x.png */, + D424A60E1CBBB0F90076F44D /* center_qrcode_line_img@2x.png */, + D424A60F1CBBB0F90076F44D /* center_qrcode_rightdown_img@2x.png */, + D424A6101CBBB0F90076F44D /* center_qrcode_rightup_img@2x.png */, + ); + path = Resources; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -202,7 +225,7 @@ TargetAttributes = { CE2960171987F124008FA93B = { CreatedOnToolsVersion = 6.0; - DevelopmentTeam = 5SJ773RP6R; + DevelopmentTeam = 84LY8T43ZV; }; CE29602D1987F124008FA93B = { CreatedOnToolsVersion = 6.0; @@ -234,6 +257,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D424A6151CBBB0F90076F44D /* center_qrcode_rightup_img@2x.png in Resources */, + D424A6111CBBB0F90076F44D /* center_qrcode_leftdown_img@2x.png in Resources */, + D424A6131CBBB0F90076F44D /* center_qrcode_line_img@2x.png in Resources */, + D424A6141CBBB0F90076F44D /* center_qrcode_rightdown_img@2x.png in Resources */, + D424A6121CBBB0F90076F44D /* center_qrcode_leftup_img@2x.png in Resources */, CE2960271987F124008FA93B /* Main.storyboard in Resources */, CE2960291987F124008FA93B /* Images.xcassets in Resources */, ); @@ -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; }; @@ -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; }; diff --git a/Example/QRCodeReaderViewControllerExample/Base.lproj/Main.storyboard b/Example/QRCodeReaderViewControllerExample/Base.lproj/Main.storyboard index ae6cb57..32b67cd 100644 --- a/Example/QRCodeReaderViewControllerExample/Base.lproj/Main.storyboard +++ b/Example/QRCodeReaderViewControllerExample/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -19,7 +19,6 @@ - diff --git a/Example/QRCodeReaderViewControllerExample/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/QRCodeReaderViewControllerExample/Images.xcassets/AppIcon.appiconset/Contents.json index 91bf9c1..eeea76c 100644 --- a/Example/QRCodeReaderViewControllerExample/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/QRCodeReaderViewControllerExample/Images.xcassets/AppIcon.appiconset/Contents.json @@ -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", @@ -44,6 +59,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/QRCodeReaderViewController/QRCodeReaderView.m b/QRCodeReaderViewController/QRCodeReaderView.m index 60a1192..2b86fcd 100644 --- a/QRCodeReaderViewController/QRCodeReaderView.m +++ b/QRCodeReaderViewController/QRCodeReaderView.m @@ -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 @@ -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 diff --git a/QRCodeReaderViewController/Resources/center_qrcode_leftdown_img@2x.png b/QRCodeReaderViewController/Resources/center_qrcode_leftdown_img@2x.png new file mode 100644 index 0000000..29d8f58 Binary files /dev/null and b/QRCodeReaderViewController/Resources/center_qrcode_leftdown_img@2x.png differ diff --git a/QRCodeReaderViewController/Resources/center_qrcode_leftup_img@2x.png b/QRCodeReaderViewController/Resources/center_qrcode_leftup_img@2x.png new file mode 100644 index 0000000..bc40869 Binary files /dev/null and b/QRCodeReaderViewController/Resources/center_qrcode_leftup_img@2x.png differ diff --git a/QRCodeReaderViewController/Resources/center_qrcode_line_img@2x.png b/QRCodeReaderViewController/Resources/center_qrcode_line_img@2x.png new file mode 100644 index 0000000..5db3f28 Binary files /dev/null and b/QRCodeReaderViewController/Resources/center_qrcode_line_img@2x.png differ diff --git a/QRCodeReaderViewController/Resources/center_qrcode_rightdown_img@2x.png b/QRCodeReaderViewController/Resources/center_qrcode_rightdown_img@2x.png new file mode 100644 index 0000000..dddbc76 Binary files /dev/null and b/QRCodeReaderViewController/Resources/center_qrcode_rightdown_img@2x.png differ diff --git a/QRCodeReaderViewController/Resources/center_qrcode_rightup_img@2x.png b/QRCodeReaderViewController/Resources/center_qrcode_rightup_img@2x.png new file mode 100644 index 0000000..e1c247e Binary files /dev/null and b/QRCodeReaderViewController/Resources/center_qrcode_rightup_img@2x.png differ