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

Make sure visual scan area works #45

Open
wants to merge 1 commit 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
26 changes: 15 additions & 11 deletions QRCodeReaderViewController/QRCodeReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#import "QRCodeReader.h"
#import "QRCodeReaderView.h"

@interface QRCodeReader () <AVCaptureMetadataOutputObjectsDelegate>
@property (strong, nonatomic) AVCaptureDevice *defaultDevice;
Expand Down Expand Up @@ -248,18 +249,21 @@ - (void)setCompletionWithBlock:(void (^) (NSString *resultAsString))completionBl

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
for (AVMetadataObject *current in metadataObjects) {
if ([current isKindOfClass:[AVMetadataMachineReadableCodeObject class]]
&& [_metadataObjectTypes containsObject:current.type]) {
NSString *scannedResult = [(AVMetadataMachineReadableCodeObject *)current stringValue];

if (_completionBlock) {
_completionBlock(scannedResult);
}

break;
for (AVMetadataObject *current in metadataObjects) {
if ([current isKindOfClass:[AVMetadataMachineReadableCodeObject class]] && [_metadataObjectTypes containsObject:current.type]) {
NSString *scannedResult = [(AVMetadataMachineReadableCodeObject *)current stringValue];
AVMetadataObject* transformed = [self.previewLayer transformedMetadataObjectForMetadataObject:current];
CGRect scanarea = [QRCodeReaderView scanArea];
if (CGRectIntersectsRect(scanarea, transformed.bounds))
{
NSLog(@"/////// Intersect");
if (_completionBlock) {
_completionBlock(scannedResult);
break;
}
}
}
}
}
}

@end
2 changes: 1 addition & 1 deletion QRCodeReaderViewController/QRCodeReaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
* @since 2.0.0
*/
@interface QRCodeReaderView : UIView

+(CGRect)scanArea;
@end
12 changes: 10 additions & 2 deletions QRCodeReaderViewController/QRCodeReaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#import "QRCodeReaderView.h"

static CGRect scanarea;

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

Expand All @@ -38,7 +40,7 @@ - (id)initWithFrame:(CGRect)frame
if ((self = [super initWithFrame:frame])) {
[self addOverlay];
}

scanarea = CGRectZero;
return self;
}

Expand All @@ -58,10 +60,16 @@ - (void)drawRect:(CGRect)rect

CGRect offsetRect = CGRectOffset(innerRect, 0, 15);


scanarea = offsetRect;

_overlay.path = [UIBezierPath bezierPathWithRoundedRect:offsetRect cornerRadius:5].CGPath;
}

+(CGRect)scanArea
{
return scanarea;
}

#pragma mark - Private Methods

- (void)addOverlay
Expand Down