GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix focus and popup alertview · cgreening/BarCodeExample@38509fa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • BarCodeReader
    • Base.lproj
      • Main.storyboard
    • CMGViewController.m
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎BarCodeReader/Base.lproj/Main.storyboard‎

Copy file name to clipboard
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3676"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
56
</dependencies>
67
<scenes>
7-
<!--class Prefix:identifier View Controller-->
8+
<!--View Controller-->
89
<scene sceneID="ufC-wZ-h7g">
910
<objects>
1011
<viewController id="vXZ-lx-hvc" customClass="CMGViewController" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="bgG-MK-LWh"/>
14+
<viewControllerLayoutGuide type="bottom" id="Gbq-OO-ZnK"/>
15+
</layoutGuides>
1116
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
1217
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
1318
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
19+
<subviews>
20+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Scanning" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9Lj-3T-gcv">
21+
<rect key="frame" x="16" y="527" width="288" height="21"/>
22+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
23+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
24+
<color key="textColor" red="0.25098040699958801" green="0.50196081399917603" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
25+
<nil key="highlightedColor"/>
26+
</label>
27+
</subviews>
1428
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
1529
</view>
30+
<connections>
31+
<outlet property="barcode" destination="9Lj-3T-gcv" id="0ms-WI-5B3"/>
32+
</connections>
1633
</viewController>
1734
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
1835
</objects>
@@ -23,4 +40,4 @@
2340
<simulatedOrientationMetrics key="orientation"/>
2441
<simulatedScreenMetrics key="destination" type="retina4"/>
2542
</simulatedMetricsContainer>
26-
</document>
43+
</document>
Collapse file

‎BarCodeReader/CMGViewController.m‎

Copy file name to clipboardExpand all lines: BarCodeReader/CMGViewController.m
+48-26Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#import "CMGViewController.h"
1010
#import "CMGOverlayView.h"
1111

12-
@interface CMGViewController ()<AVCaptureMetadataOutputObjectsDelegate>
12+
@interface CMGViewController ()<AVCaptureMetadataOutputObjectsDelegate, UIAlertViewDelegate>
1313

1414
@property(nonatomic, strong) AVCaptureSession *session;
1515
@property(nonatomic, strong) UIView *previewView;
1616
@property(nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
1717
@property(nonatomic, strong) CMGOverlayView *overlayView;
18+
@property(nonatomic, strong) IBOutlet UILabel *barcode;
1819

1920
@end
2021

@@ -51,9 +52,21 @@ - (void)viewDidLoad
5152
break;
5253
}
5354
}
55+
56+
NSError *error = nil;
57+
[camera lockForConfiguration:&error];
58+
if([camera isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
59+
[camera setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
60+
}
61+
if([camera isAutoFocusRangeRestrictionSupported]) {
62+
[camera setAutoFocusRangeRestriction:AVCaptureAutoFocusRangeRestrictionNear];
63+
}
64+
[camera unlockForConfiguration];
65+
if(error) {
66+
NSLog(@"Erorr locking for configuration, %@", error);
67+
}
5468

5569
// Create a AVCaptureInput with the camera device
56-
NSError *error=nil;
5770
AVCaptureDeviceInput *cameraInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error];
5871
if (cameraInput == nil) {
5972
NSLog(@"Error to create camera capture:%@",error);
@@ -74,7 +87,7 @@ - (void)viewDidLoad
7487
AVMetadataObjectTypeEAN13Code,
7588
AVMetadataObjectTypeEAN8Code,
7689
AVMetadataObjectTypePDF417Code,
77-
AVMetadataObjectTypeQRCode,
90+
// AVMetadataObjectTypeQRCode,
7891
AVMetadataObjectTypeUPCECode]];
7992

8093
NSMutableArray *supportedMetaDataTypes = [NSMutableArray array];
@@ -93,32 +106,41 @@ - (void)viewDidLoad
93106
[self.session startRunning];
94107
}
95108

109+
-(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
110+
[self.session startRunning];
111+
}
112+
96113
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
97-
// draw where the recognised data is - for 1D barcodes this turns out to be just a line accross the code. For 2D barcodes it's a bit more interesting
98-
CGMutablePathRef pathRef = CGPathCreateMutable();
99-
CGAffineTransform transform = CGAffineTransformMakeScale(self.overlayView.bounds.size.width, self.overlayView.bounds.size.height);
100-
101-
for(AVMetadataMachineReadableCodeObject *recognizedObject in metadataObjects) {
102-
NSLog(@"%@", recognizedObject.stringValue);
103-
104-
CGPoint p1 = CGPointMake(0.4, 0.4);
105-
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[0]), &p1);
106-
CGPoint p2 = CGPointMake(0.5, 0.4);
107-
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[1]), &p2);
108-
CGPoint p3 = CGPointMake(0.5, 0.5);
109-
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[2]), &p3);
110-
CGPoint p4 = CGPointMake(0.4, 0.5);
111-
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[3]), &p4);
112-
113-
CGPathMoveToPoint(pathRef, &transform, 1-p1.y, p1.x);
114-
CGPathAddLineToPoint(pathRef, &transform, 1-p2.y, p2.x);
115-
CGPathAddLineToPoint(pathRef, &transform, 1-p3.y, p3.x);
116-
CGPathAddLineToPoint(pathRef, &transform, 1-p4.y, p4.x);
117-
CGPathCloseSubpath(pathRef);
114+
if(metadataObjects.count > 0) {
115+
dispatch_async(dispatch_get_main_queue(), ^{
116+
AVMetadataMachineReadableCodeObject *recognizedObject = metadataObjects.firstObject;
117+
self.barcode.text = recognizedObject.stringValue;
118+
[[[UIAlertView alloc] initWithTitle:@"Scanned" message:recognizedObject.stringValue delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
119+
});
120+
[self.session stopRunning];
121+
// draw where the recognised data is - for 1D barcodes this turns out to be just a line accross the code. For 2D barcodes it's a bit more interesting
122+
CGMutablePathRef pathRef = CGPathCreateMutable();
123+
CGAffineTransform transform = CGAffineTransformMakeScale(self.overlayView.bounds.size.width, self.overlayView.bounds.size.height);
118124

125+
for(AVMetadataMachineReadableCodeObject *recognizedObject in metadataObjects) {
126+
CGPoint p1 = CGPointMake(0.4, 0.4);
127+
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[0]), &p1);
128+
CGPoint p2 = CGPointMake(0.5, 0.4);
129+
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[1]), &p2);
130+
CGPoint p3 = CGPointMake(0.5, 0.5);
131+
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[2]), &p3);
132+
CGPoint p4 = CGPointMake(0.4, 0.5);
133+
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)(recognizedObject.corners[3]), &p4);
134+
135+
CGPathMoveToPoint(pathRef, &transform, 1-p1.y, p1.x);
136+
CGPathAddLineToPoint(pathRef, &transform, 1-p2.y, p2.x);
137+
CGPathAddLineToPoint(pathRef, &transform, 1-p3.y, p3.x);
138+
CGPathAddLineToPoint(pathRef, &transform, 1-p4.y, p4.x);
139+
CGPathCloseSubpath(pathRef);
140+
}
141+
((CAShapeLayer *) self.overlayView.layer).path = pathRef;
142+
CGPathRelease(pathRef);
119143
}
120-
((CAShapeLayer *) self.overlayView.layer).path = pathRef;
121-
CGPathRelease(pathRef);
122144
}
123145

124146
-(void) viewDidLayoutSubviews {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.